home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / diskmags / 0022-3.564 / dmg-0139 / news.txt / guide1.asc < prev    next >
Text File  |  1997-04-16  |  141KB  |  3,408 lines

  1.       
  2.                              A Hitchhiker's
  3.                               Guide to the
  4.                                   BIOS
  5.       
  6.       
  7.                            (C)1985 Atari Corp.
  8.                            All Rights Reserved
  9.       
  10.       
  11.                                ~~~OOOO~~~    
  12.       
  13.       
  14.                               Introduction
  15.                               ------------
  16.       
  17.       Remember, DON'T PANIC.  This is the new, improved  introduc-
  18.       tion  to the Hitchhiker's Guide to the BIOS, which describes
  19.       the BIOS (and many other aspects)  of  Atari's  ST  computer
  20.       series.   The introduction still won't tell you much, but at
  21.       least it tells you not to panic.
  22.       
  23.       The Guide's intended audience:
  24.       
  25.           Application writers (who will find some of the func-
  26.           tions and hints here invaluable);
  27.       
  28.           Those wishing to  make  use  of  some  of  the  ST's
  29.           hardware-specific  features (hacking palette colors,
  30.           configuring the RS232 port, and so on);
  31.       
  32.           Those  writing  device  drivers,  video  games,   or
  33.           cartridge-based applications;
  34.       
  35.           The habitually curious (including  trivia  trippers,
  36.           information junkies, and documentation addicts).
  37.       
  38.       
  39.       For many reasons this should still be considered  a  prelim-
  40.       inary document.  A whole host of things remain undocumented,
  41.       many GEMDOS issues have not  even  been  approached  by  our
  42.       friends  at Digital Research, and there are a /whole lot/ of
  43.       features we'd like to add to the software.
  44.  
  45.  
  46.                              ~~~OOOO~~~      
  47.             
  48.       
  49.                           GEMDOS BIOS Calls
  50.                           -----------------
  51.  
  52.                              Description
  53.                                  and
  54.                     Deviation from the GEMDOS Spec.
  55.       
  56.       
  57.       The ST BIOS, contrary to the GEMDOS specification, is  call-
  58.       able from the 68000's user mode.
  59.       
  60.       The BIOS is re-entrant to three levels.  That is, there  may
  61.       be  up  to three recursive BIOS calls before the system runs
  62.       into trouble.  No level checking  is  performed;  the  first
  63.       sign  of an overflow will be mysterious system behavior, and
  64.       an eventual crash.
  65.       
  66.       Applications should NOT attempt disk or  printer  I/O  (this
  67.       includes getbpb calls, and standard-output redirected to the
  68.       printer device) in critical-error, system-timer or  process-
  69.       terminate handlers.
  70.       
  71.                                   NOTE
  72.       
  73.           The BIOS modifies the function number (and  the  re-
  74.           turn  address)  pushed  on the stack by the applica-
  75.           tion.  The function number on the stack will be ZERO
  76.           on  return.   [For  the  curious: this feature saved
  77.           several cycles per BIOS call ...]
  78.       
  79.       
  80.        (0) getmpb
  81.            VOID getmpb(p_mpb)
  82.            LONG p_mpb;
  83.                  Upon entry, 'p_mpb'  points  to  a  'sizeof(MPB)'
  84.                  block  to  be  filled  in with the system initial
  85.                  Memory Parameter Block.  Upon return, the MPB  is
  86.                  filled in.
  87.       
  88.                  Structures are:
  89.       
  90.                      #define MPB     struct mpb
  91.                      #define MD      struct md
  92.                      #define PD      struct pd
  93.       
  94.                      MPB {
  95.                          MD *mp_mfl;         /* memory free list */
  96.                          MD *mp_mal;         /* memory allocated list */
  97.                          MD *mp_rover;       /* roving ptr */
  98.                      };
  99.       
  100.                      MD {
  101.                          MD *m_link;         /* next MD (or NULL) */
  102.                          long m_start;       /* saddr of block */
  103.                          long m_length;      /* #bytes in block */
  104.                          PD *m_own;          /* owner's process descriptor */
  105.                      };
  106.       
  107.                  [See  `System  Variables'  for  more  information
  108.                  about setting up the initial TPA.]
  109.       
  110.        (1) bconstat
  111.            WORD bconstat(dev)
  112.            WORD dev;
  113.                  Return character-device input status,  D0.L  will
  114.                  be  $0000 if no characters available, or $ffff if
  115.                  (at least one) character is available.  'dev' can
  116.                  be one of:
  117.       
  118.                          0   PRT: (printer, the parallel port)
  119.                          1   AUX: (aux device, the RS232 port)
  120.                          2   CON: (console, the screen)
  121.                          3   MIDI port (Atari extension)
  122.                          4   Keyboard port (Atari extension)
  123.       
  124.                  Legal operations on character devices are:
  125.       
  126.                                      (0)     (1)     (2)     (3)     (4)
  127.                      Operation       PRT     AUX     CON     MIDI    KBD
  128.                      ---------       ----    ----    ----    ----    ----
  129.                      bconstat()      no      yes     yes     yes     no
  130.                      bconin()        yes     yes     yes     yes     no
  131.                      bconout()       yes     yes     yes     yes     yes
  132.                      bcostat()       yes     yes     yes     yes     yes
  133.       
  134.       
  135.        (2) bconin
  136.            WORD bconin(dev)
  137.            WORD dev;
  138.                  'dev' is the character device number described in
  139.                  function 1.
  140.       
  141.                  Does not return until a character has been  input
  142.                  (busy-wait).   It  returns the character value in
  143.       
  144.                  D0.L, with the high word zero.
  145.       
  146.                  For the console (CON:, device 2) it  returns  the
  147.                  IBM-PC compatible scancode in the low byte of the
  148.                  upper word, and the Ascii character  in  the  low
  149.                  byte of the low word.
  150.       
  151.                  If bit 3 in the system variable 'conterm' is set,
  152.                  then the high byte of the upper word will contain
  153.                  the value of the system  variable  'kbshift'  for
  154.                  that  keystroke.   [The  default  state for 'con-
  155.                  term%%3' is OFF.]
  156.  
  157.       
  158.        (3) bconout
  159.            VOID bconout(dev, c)
  160.            WORD dev, c;
  161.                  'dev' is the character device number described in
  162.                  function 1.
  163.       
  164.                  Output character 'c' to  the  device.   Does  not
  165.                  return until the character has been written.
  166.  
  167.       
  168.        (4) rwabs
  169.            LONG rwabs(rwflag, buf, count, recno, dev)
  170.            WORD rwflag;
  171.            LONG buf;
  172.            WORD count, recno, dev;
  173.                  Read  or  write  logical  sectors  on  a  device.
  174.                  'rwflag' is one of:
  175.       
  176.                          0   read
  177.                          1   write
  178.                          2   read, do not affect media-change
  179.                          3   write, do not affect media-change
  180.       
  181.                  'buf' points to a buffer  to  read  or  write  to
  182.                  (unaligned  transfers -- on odd boundaries -- are
  183.                  permitted, but they are slow).   'count'  is  the
  184.                  number  of  sectors  to transfer.  'recno' is the
  185.                  logical sector number to start the  transfer  at.
  186.                  'dev'  is the device number, and on the ST is one
  187.                  of:
  188.       
  189.                          0   Floppy drive A:
  190.                          1   Floppy drive B: (or "logical" drive A:
  191.                              on single-disk systems).
  192.                          2+  Hard disks, networks, etc.
  193.       
  194.                  On return, 0L indicates a  successful  operation.
  195.                  Any negative number indicates an error condition.
  196.                  (It is the responsibility of the BIOS  to  detect
  197.                  media  changes,  and return the appropriate error
  198.                  code).
  199.       
  200.                  Modes 2 and 3 force  a  physical  disk  operation
  201.                  that  will NOT affect media change, nor result in
  202.                  one (this allows the GEMDOS disk  formatter,  for
  203.                  instance, to read and write logical sectors after
  204.                  formatting a disk, and still allow  the  BIOS  to
  205.                  recognize  a media change on the volume just for-
  206.                  matted).
  207.       
  208.                  [explain about "insert-disk" critical error  hack
  209.                  for single-drive systems]
  210.  
  211.       
  212.        (5) setexc
  213.            LONG setexc(vecnum, vec)
  214.            WORD vecnum;
  215.            LONG vec;
  216.                  'vecnum' is the number of the vector  to  get  or
  217.                  set.  'vec' is the address to setup in the vector
  218.                  slot; no set  is  done  if  'vec'  is  -1L.   The
  219.                  vector's previous value is returned.
  220.       
  221.                  Vectors $00 through  $FF  are  reserved  for  the
  222.                  68000.
  223.       
  224.                  Logical vectors $100 through  $1FF  are  reserved
  225.                  for GEMDOS.  Vectors currently implemented are:
  226.       
  227.                        $100  System timer interrupt
  228.                        $101  Critical error handler
  229.                        $102  Process terminate hook
  230.                      $103..$107:  Currently unused, reserved
  231.       
  232.                  Logical vectors $200 through $FFFF  are  reserved
  233.                  for  OEM use.  The ST BIOS makes no provision for
  234.                  these.
  235.  
  236.       
  237.        (6) tickcal
  238.            LONG tickcal()
  239.                  Returns a system-timer calibration value, to  the
  240.                  nearest millisecond.
  241.       
  242.                  This is a silly function,  since  the  number  of
  243.                  elapsed  milliseconds is passed on the stack dur-
  244.                  ing a system-timer trap.
  245.  
  246.       
  247.        (7) *getbpb
  248.            BPB *getbpb(dev)
  249.            WORD dev;
  250.                  'dev' is a device number (0 for  drive  A,  etc.)
  251.                  Returns a pointer to the BIOS Parameter Block for
  252.                  the specified drive, or 0L if (for  some  reason)
  253.                  the BPB cannot be determined.
  254.  
  255.       
  256.        (8) bcostat
  257.            LONG bcostat(dev)
  258.                  'dev' is a character device number, as  in  func-
  259.                  tion 1.  Returns character output status:
  260.       
  261.                         -1   Device is ready to send (no waiting on
  262.                              next device-output call).
  263.                          0   Device is not ready to send.
  264.       
  265.       
  266.        (9) mediach
  267.            LONG mediach(dev)
  268.            WORD dev;
  269.                  'dev' is a drive number.  Returns one of:
  270.       
  271.                          0   Media definitely has not changed
  272.                          1   Media /might/ have changed
  273.                          2   Media definitely has changed
  274.       
  275.                  GEMDOS will respond to a return value of '1' with
  276.                  a  read  operation.  If the BIOS detects an abso-
  277.                  lute  media  change,  it  will  return  a  "media
  278.                  change" error at that time.
  279.       
  280.  
  281.        (10) drvmap
  282.            LONG drvmap()
  283.                  Returns a bit-vector that contains a '1' in a bit
  284.                  position  (0 .. 31) when a drive is available for
  285.                  that bit, or a 0 if there is no  drive  available
  286.                  for the bit.
  287.       
  288.                  Installable disk drivers must correctly  maintain
  289.                  the longword '_drvbits' [see: System Variables].
  290.       
  291.  
  292.        (11) kbshift
  293.            LONG kbshift(mode)
  294.            WORD mode;
  295.                  If 'mode'  is  non-negative,  sets  the  keyboard
  296.                  shift  bits accordingly and returns the old shift
  297.                  bits.  If 'mode' is less than zero,  returns  the
  298.                  IBM-PC  compatible state of the shift keys on the
  299.                  keyboard, as a bit-vector in the low byte of D0.
  300.       
  301.                  Bit assignments are:
  302.       
  303.                        0     Right shift key
  304.                        1     Left shift key
  305.                        2     Control key
  306.                        3     ALT key
  307.                        4     Caps-lock
  308.                        5     Right mouse button (CLR/HOME)
  309.                        6     Left mouse button (INSERT)
  310.                        7     (reserved, currently zero)
  311.       
  312.       
  313.                              ~~~OOOO~~~      
  314.  
  315.  
  316.                         Extended BIOS Functions
  317.                         -----------------------      
  318.       
  319.       These functions are available through trap 14.  The  calling
  320.       conventions  are  the  same as for trap 13.  Contrary to the
  321.       GEMDOS specification, the caller does  NOT  have  to  be  in
  322.       supervisor  mode.   It  is  the  caller's  responsibility to
  323.       cleanup arguments passed to the trap (as per the  C  calling
  324.       standard).
  325.       
  326.       A typical trap handler, one that works  from  a  C  binding,
  327.       might be:
  328.       
  329.           _trap14:
  330.                   move.l  (sp)+,tr14ret   ; pop ret addr
  331.                   trap    #14             ; do BIOS func
  332.                   move.l  tr14ret,-(sp)   ; return to
  333.                   rts                     ;  caller
  334.       
  335.                   bss
  336.           tr14ret: ds.l                   ; saved ret. addr
  337.       
  338.       and it might be used like:
  339.       
  340.           /*
  341.            * Stupid way to set the screen to a single value.
  342.            */
  343.           set_screen_to(v)
  344.           WORD v;
  345.           {
  346.               extern long trap14();
  347.               register WORD *p;
  348.               register int i;
  349.       
  350.               scrbase = (WORD *)trap14(3);
  351.               for (i = 0x4000; i; --i)
  352.                   *p++ = v;
  353.           }
  354.       
  355.           /*
  356.            * Xor palettes in a range with a given value
  357.            */
  358.           set_palette_range(start, fin, v)
  359.           WORD start, fin, v;
  360.           {
  361.               while (start <= fin)
  362.                   trap14(7, trap14(7, -1) ^ v);
  363.           }
  364.       
  365.       
  366.        (0) initmous
  367.            VOID initmous(type, param, vec)
  368.            WORD type;
  369.            LONG param, vec;
  370.                  Initialize mouse packet handler.  'type'  is  one
  371.                  of:
  372.       
  373.                       type   Action
  374.       
  375.                        0     disable mouse
  376.                        1     enable mouse, in relative mode
  377.                        2     enable mouse, in absolute mode
  378.                        3     (unused)
  379.                        4     enable mouse, in keycode mode
  380.       
  381.                   'param' points to a parameter block that  should
  382.                  look like:
  383.       
  384.                      struct param {
  385.                          BYTE topmode;
  386.                          BYTE buttons;
  387.                          BYTE xparam;
  388.                          BYTE yparam;
  389.                      };
  390.       
  391.                  'topmode' should be:
  392.       
  393.                        0     Y_position == 0 at bottom
  394.                        1     Y_position == 0 at top
  395.       
  396.                  'buttons' is a parameter for the keyboard's  "set
  397.                  mouse buttons" command.
  398.       
  399.                  'xparam' and 'yparam' are the X and Y  threshold,
  400.                  scale or delta factors, depending on the mode the
  401.                  mouse is being placed in.
  402.       
  403.                  For mouse absolute mode,  some  extra  parameters
  404.                  immediately follow the parameter block:
  405.       
  406.                      struct extra {
  407.                          WORD xmax;
  408.                          WORD ymax;
  409.                          WORD xinitial;
  410.                          WORD yinitial;
  411.                      };
  412.       
  413.                  'xmax' and 'ymax' specify the  maximum  X  and  Y
  414.                  mouse   positions.    'xinitial'  and  'yinitial'
  415.                  specify the initial X and Y mouse position.
  416.       
  417.                  'vec' points to a mouse  interrupt  handler;  see
  418.                  extended  function  number  34,  'kbdvbase',  for
  419.                  further   information   about   ikbd    subsystem
  420.                  handlers.
  421.       
  422.  
  423.        (1) ssbrk
  424.            LONG ssbrk(amount)
  425.            WORD amount;
  426.                  Reserve 'amount' bytes from the  top  of  memory.
  427.                  Returns  a long pointing to the base of the allo-
  428.                  cated  memory.   This  function  MUST  be  called
  429.                  before the OS is initialized.
  430.       
  431.                  'ssbrk' is actually pretty useless.  It DOES  NOT
  432.                  work  after GEMDOS has been brought up, since the
  433.                  TPA has already been set up.
  434.       
  435.  
  436.        (2) _physBase
  437.            LONG _physBase()
  438.                  Get the screen's physical base  address  (at  the
  439.                  beginning of the next vblank).
  440.       
  441.  
  442.        (3) _logBase
  443.            LONG _logBase()
  444.                  Get the screen's logical base, right away.   This
  445.                  is the location that GSX uses when drawing to the
  446.                  screen.
  447.  
  448.       
  449.        (4) _getRez
  450.            WORD _getRez()
  451.                  Get the screen's current resolution (returning 0,
  452.                  1 or 2).
  453.       
  454.  
  455.        (5) _setScreen
  456.            VOID _setScreen(logLoc, physLoc, rez)
  457.            LONG logLoc, physLoc;
  458.            WORD rez;
  459.                  Set the logical  screen  location  (logLoc),  the
  460.                  physical  screen location (physLoc), and the phy-
  461.                  sical screen resolution.  Negative parameters are
  462.                  ignored (making it possible, for instance, to set
  463.                  screen  resolution  without   changing   anything
  464.                  else).
  465.       
  466.                  The logical screen location changes  immediately.
  467.                  The physical screen location hardware register is
  468.                  changed immediately, but the new screen  location
  469.                  will take effect after the next vertical retrace.
  470.       
  471.                  When  resolution  is  changed,  the   screen   is
  472.                  cleared, the cursor is homed, and the VT52 termi-
  473.                  nal emulator state is reset.
  474.       
  475.  
  476.        (6) _setPallete
  477.            VOID _setPallete(palettePtr)
  478.            LONG palettePtr;
  479.                  Set the contents of the hardware palette register
  480.                  (all  16 color entries) from the 16 words pointed
  481.                  to by 'palettePtr'.  'paletteptr' MUST  be  on  a
  482.                  word  boundary.   The  palette  assignment  takes
  483.                  place at the beginning of the next vertical blank
  484.                  interrupt.
  485.       
  486.  
  487.        (7) _setColor
  488.            WORD _setColor(colorNum, color)
  489.            WORD colorNum, color;
  490.                  Set the palette number 'colorNum' in the hardware
  491.                  palette table to the given color.  Return the old
  492.                  color in  D0.W.   If  'color'  is  negative,  the
  493.                  hardware register is not changed.
  494.       
  495.  
  496.        (8) _floprd
  497.            WORD  _floprd(buf,  filler,  devno,  sectno,   trackno,
  498.                  sideno, count)
  499.            LONG buf, filler;
  500.            WORD devno, sectno, trackno, sideno, count;
  501.                  Read one or more  sectors  from  a  floppy  disk.
  502.                  'filler' is an unused longword.  'buf' must point
  503.                  to a word-aligned buffer large enough to  contain
  504.                  the  number of sectors requested.  'devno' is the
  505.                  floppy number (0 or 1).  'sectno' is  the  sector
  506.                  number  to  start reading from (usually 1 through
  507.                  9).  'trackno' is the track number  to  seek  to.
  508.                  'sideno'  is  the side number to select.  'count'
  509.                  is the number of sectors to read (which  must  be
  510.                  less  than  or equal to the number of sectors per
  511.                  track).
  512.       
  513.                  On return, D0 contains a status code.  If  D0  is
  514.                  zero, the operation succeeded.  If D0 is nonzero,
  515.                  the operation failed (and D0  contains  an  error
  516.                  number).
  517.       
  518.  
  519.        (9) _flopwr
  520.            WORD  _flopwr(buf,  filler,  devno,  sectno,   trackno,
  521.                  sideno, count)
  522.            LONG buf, filler;
  523.            WORD devno, sectno, trackno, sideno, count;
  524.                  Write one or  more  sectors  to  a  floppy  disk.
  525.                  'buf'   must  point  to  a  word-aligned  buffer.
  526.                  'filler' is an unused longword.  'devno'  is  the
  527.                  floppy  number  (0 or 1).  'sectno' is the sector
  528.                  number to start writing to (usually 1 through 9).
  529.                  'trackno'   is  the  track  number  to  seek  to.
  530.                  'sideno' is the side number to  select.   'count'
  531.                  is  the number of sectors to write (which must be
  532.                  less than or equal to the number of  sectors  per
  533.                  track).
  534.       
  535.                  On return, D0 contains a status code.  If  D0  is
  536.                  zero, the operation succeeded.  If D0 is nonzero,
  537.                  the operation failed (and D0  contains  an  error
  538.                  number).
  539.       
  540.                  Writing to the boot sector  (sector  1,  side  0,
  541.                  track 0) will cause the media to enter the "might
  542.                  have changed" state.  This will be  reflected  on
  543.                  the next rwabs() or mediach() BIOS call.
  544.       
  545.  
  546.        (10) _flopfmt
  547.            WORD _flopfmt(buf, filler, devno, spt, trackno, sideno,
  548.                  interlv, magic, virgin)
  549.            LONG buf, filler;
  550.            WORD devno, spt, trackno, sideno, interlv, virgin;
  551.            LONG magic;
  552.                  Format a track on  a  floppy  disk.   'buf'  must
  553.                  point  to  a  word-aligned buffer large enough to
  554.                  hold an entire track image  (8K  for  9  sectors-
  555.                  per-track).   'filler'  is  an  unused  longword.
  556.                  'devno' is the floppy  drive  number  (0  or  1).
  557.                  'spt'  is the number of sectors-per-track to for-
  558.                  mat (usually 9).  'trackno' is the  track  number
  559.                  to  format  (usually  0  to 79).  'sideno' is the
  560.                  side number to format (0 or 1).  'interlv' is the
  561.                  sector-interleave factor (usually 1).  'magic' is
  562.                  a magic number that MUST be the value  $87654321.
  563.                  'virgin' is a word fill value for new sectors.
  564.       
  565.                  On return, D0 contains a status code.  If  D0  is
  566.                  zero, the operation succeeded.  If D0 is nonzero,
  567.                  the operation failed (and D0  contains  an  error
  568.                  number).   The format function can soft-fail when
  569.                  it finds bad sectors during the verify pass.  The
  570.                  caller  has the choice of attempting to re-format
  571.                  the media, or recording the bad sectors  so  they
  572.                  will not be included in the file system.
  573.       
  574.                  A  null-terminated  (0.W)  list  of  bad   sector
  575.                  numbers  is returned in the buffer.  They are not
  576.                  necessarily in numerical order.  (If  there  were
  577.                  no bad sectors, the first word in the buffer will
  578.                  be zero.)
  579.       
  580.                  A good value for 'virgin'  is  $E5E5.   The  high
  581.                  nibble  of  each  byte  in the 'virgin' parameter
  582.                  must not be equal to $F.  Resist  the  temptation
  583.                  to  format  a  disk  with  sectors initialized to
  584.                  zero.
  585.       
  586.                  Formatting a track will cause the media to  enter
  587.                  the  "definitely  changed"  state.   This will be
  588.                  reflected on the next rwabs() or  mediach()  BIOS
  589.                  call.
  590.       
  591.  
  592.        (11) used-by-BIOS
  593.            VOID used-by-BIOS()
  594.                  [Obsolete function]
  595.       
  596.  
  597.        (12) midiws
  598.            VOID midiws(cnt, ptr)
  599.            WORD cnt;
  600.            LONG ptr;
  601.                  Writes a string to the MIDI port.  'cnt'  is  the
  602.                  number  of characters to write, minus one.  'ptr'
  603.                  points to a vector of characters to write.
  604.       
  605.  
  606.        (13) _mfpint
  607.            VOID _mfpint(interno, vector)
  608.            WORD interno;
  609.            LONG vector;
  610.                  Set the MFP interrupt number 'interno' (0 to  15)
  611.                  to 'vector'.  The old vector is written over (and
  612.                  thus unrecoverable).
  613.       
  614.  
  615.        (14) iorec
  616.            LONG iorec(devno)
  617.            WORD devno;
  618.                  Returns a pointer  to  a  serial  device's  input
  619.                  buffer record.  'devno' is one of:
  620.       
  621.                      devno   Device
  622.                      -----   --------
  623.                        0     RS232
  624.                        1     Keyboard
  625.                        2     MIDI
  626.       
  627.                  The structure of the record is:
  628.       
  629.                      struct iorec
  630.                      {
  631.                          LONG ibuf;          /* pointer to buffer */
  632.                          WORD ibufsiz;       /* size of buffer */
  633.                          WORD ibufhd;        /* head index */
  634.                          WORD ibuftl;        /* tail index */
  635.                          WORD ibuflow;       /* low-water mark */
  636.                          WORD ibufhi;        /* high-water mark */
  637.                      };
  638.       
  639.                  For RS-232, an output-buffer  record  immediately
  640.                  follows  the  input-buffer record.  The format of
  641.                  the output-buffer record is identical.
  642.       
  643.                  'ibuf' points to the device's buffer.   'ibufsiz'
  644.                  is  the  buffer's size.  'ibufhi' is the buffer's
  645.                  high-water mark.  'ibuflow' is the buffer's  low-
  646.                  water mark.
  647.       
  648.                  If flow control is  enabled  and  the  number  of
  649.                  characters  in  the buffer reaches the high-water
  650.                  mark, the ST requests  (according  to  the  flow-
  651.                  control  protocol)  the  sender  to  stop sending
  652.                  characters.  When the number of characters in the
  653.                  buffer  drops  below  the  low-water mark, the ST
  654.                  tells the sender to resume transmission.
  655.       
  656.                  The flow-control operation  is  similar  for  the
  657.                  RS-232 output record.
  658.       
  659.  
  660.        (15) rsconf
  661.            VOID rsconf(speed, flowctl, ucr, rsr, tsr, scr)
  662.            WORD speed, flowctl, ucr, rsr, tsr, scr;
  663.                  Configure RS-232 port.  If any  parameter  is  -1
  664.                  ($FFFF),  the  corresponding hardware register is
  665.                  not set.  'speed' sets the port's baud  rate,  as
  666.                  per:
  667.       
  668.                      speed         Rate (bps)
  669.                      -----         ----------
  670.                        0             19,200
  671.                        1             9600
  672.                        2             4800
  673.                        3             3600
  674.                        4             2400
  675.                        5             2000
  676.                        6             1800
  677.                        7             1200
  678.                        8             600
  679.                        9             300
  680.                        10            200
  681.                        11            150
  682.                        12            134
  683.                        13            110
  684.                        14            75
  685.                        15            50
  686.       
  687.                  'flow' sets the flow control, as per:
  688.       
  689.                      flow    Flavor
  690.                      -----   ---------
  691.                        0     No flow control [powerup default]
  692.                        1     XON/XOFF (^S/^Q)
  693.                        2     RTS/CTS
  694.                        3     XON/XOFF and RTS/CTS [is this useful?]
  695.       
  696.                  'ucr', 'rsr', 'tsr', and 'scr' set the  appropri-
  697.                  ate 68901 registers.
  698.       
  699.  
  700.        (16) keytbl
  701.            LONG keytbl(unshift, shift, capslock)
  702.            LONG unshift, shift, capslock;
  703.                  Sets pointers to the keyboard translation  tables
  704.                  for  unshifted  keys,  shifted  keys, and keys in
  705.                  caps-lock mode.  Returns a pointer to the  begin-
  706.                  ning of a structure:
  707.       
  708.                      struct keytab {
  709.                          LONG unshift;       /* -> unshift table */
  710.                          LONG shift;         /* -> shift table */
  711.                          LONG capslock;      /* -> capslock table */
  712.                      };
  713.       
  714.                  Each pointer in the structure should point  to  a
  715.                  table  128  bytes  in length.  A scancode is con-
  716.                  verted to Ascii by indexing into  the  table  and
  717.                  taking the byte there.
  718.       
  719.  
  720.        (17) _random
  721.            LONG _random()
  722.                  Returns a 24-bit psuedo-random  number  in  D0.L.
  723.                  Bits  24..31 will be zero.  The sequence /should/
  724.                  be different each time the system is  turned  on.
  725.                  [The algorithm is from vol. 2 of Knuth:
  726.       
  727.                                   S = [S * C] + K
  728.       
  729.                  where K = 1, C = 3141592621, and S is  the  seed.
  730.                  S  >>  8  is returned.  The initial value of S is
  731.                  taken from the frame-counter '_frclock'.]
  732.       
  733.                  The function's  behavior  is  surprisingly  good,
  734.                  except  that bit 0 has an /exact/ distribution of
  735.                  50%.  Therefore it is probably not a good idea to
  736.                  test  individual  bits and expect them to be well
  737.                  behaved.
  738.       
  739.  
  740.        (18) _protobt
  741.            VOID _protobt(buf, serialno, disktype, execflag)
  742.            LONG buf, serialno;
  743.            WORD disktype, execflag;
  744.                  Prototype an image of a boot  sector.   Once  the
  745.                  boot  sector image has been constructed with this
  746.                  function, write it to the volume's boot sector.
  747.       
  748.                  'buf' points to a 512-byte buffer (which may con-
  749.                  tain  garbage,  or  already contain a boot sector
  750.                  image).
  751.       
  752.                  'serialno' is a serial number to stamp  into  the
  753.                  boot  sector.   If  'serialno'  is  -1,  the boot
  754.                  sector's serial number is not changed.  If 'seri-
  755.                  alno'  is  greater  than or equal to $01000000, a
  756.                  random serial number is generated and  placed  in
  757.                  the boot sector.
  758.       
  759.                  'disktype' is either -1 (to leave the  disk  type
  760.                  information alone) or one of the following:
  761.       
  762.                      0: 40 tracks, single sided (180K)
  763.                      1: 40 tracks, double sided (360K)
  764.                      2: 80 tracks, single sided (360K)
  765.                      3: 80 tracks, double sided (720K)
  766.       
  767.                  If 'execflag' is 1, the boot sector is made  exe-
  768.                  cutable.   If 'execflag' is 0, the boot sector is
  769.                  made non-executable.  If 'execflag'  is  -1,  the
  770.                  boot  sector remains executable or non-executable
  771.                  depending on the way it was originally.
  772.       
  773.  
  774.        (19) _flopver
  775.            WORD  _flopver(buf,  filler,  devno,  sectno,  trackno,
  776.                  sideno, count)
  777.            LONG buf, filler;
  778.            WORD devno, sectno, trackno, sideno, count;
  779.                  Verify (by simply reading) one  or  more  sectors
  780.                  from  a floppy disk.  'buf' must point to a word-
  781.                  aligned 1024-byte buffer.  'filler' is an  unused
  782.                  longword.  'devno' is the floppy number (0 or 1).
  783.                  'sectno' is the sector number  to  start  reading
  784.                  from  (usually  1  through  9).  'trackno' is the
  785.                  track number to seek to.  'sideno'  is  the  side
  786.                  number  to  select.   'count'  is  the  number of
  787.                  sectors to verify (which must  be  less  than  or
  788.                  equal to the number of sectors per track).
  789.       
  790.                  On return, D0 contains a status code.  If  D0  is
  791.                  zero, the operation succeeded.  If D0 is nonzero,
  792.                  the operation failed (and D0  contains  an  error
  793.                  number).
  794.       
  795.                  A  null-terminated  (0.W)  list  of  bad   sector
  796.                  numbers  is returned in the buffer.  They are not
  797.                  necessarily in numerical order.  (If  there  were
  798.                  no bad sectors, the first word in the buffer will
  799.                  be zero.)
  800.       
  801.  
  802.        (20) scrdmp
  803.            VOID scrdmp()
  804.                  Dump screen to printer.  [Currently this  is  the
  805.                  monochrome-only  version from CES.  Will be fixed
  806.                  soon.]
  807.       
  808.  
  809.        (21) cursconf
  810.            WORD cursconf(function, operand)
  811.            WORD function, operand;
  812.                  Configure  the  "glass  terminal"  cursor.    The
  813.                  'function' code is one of the following:
  814.       
  815.                        0     Hide cursor
  816.                        1     Show cursor
  817.                        2     Cursor set to blink
  818.                        3     Cursor set not to blink
  819.                        4     Set cursor blink timer to 'operand'
  820.                        5     Return cursor blink timer value
  821.       
  822.                  The cursor blink rate is based on the video  scan
  823.                  rate  (60hz  for color, 70hz for monochrome, 50hz
  824.                  for PAL).  The 'rate' parameter is equal to  one-
  825.                  half the cycle time.
  826.       
  827.  
  828.        (22) settime
  829.            VOID settime(datetime)
  830.            LONG datetime;
  831.                  Sets the intelligent keyboard's idea of the  time
  832.                  and date.  'datetime' is a 32-bit DOS-format date
  833.                  and time (time in the low word, date in the  high
  834.                  word).
  835.       
  836.  
  837.        (23) gettime
  838.            LONG gettime()
  839.                  Interrogates the intelligent keyboard's  idea  of
  840.                  the time and date, and returns that value (in DOS
  841.                  format) as a 32-bit word.  (Time in the low word,
  842.                  date in the high word).
  843.       
  844.  
  845.        (24) bioskeys
  846.            VOID bioskeys()
  847.                  Restores the powerup  settings  of  the  keyboard
  848.                  translation tables.
  849.       
  850.  
  851.        (25) ikbdws
  852.            VOID ikbdws(cnt, ptr)
  853.            WORD cnt;
  854.            LONG ptr;
  855.                  Writes a  string  to  the  intelligent  keyboard.
  856.                  'cnt' is the number of characters to write, minus
  857.                  one.  'ptr' points to a vector of  characters  to
  858.                  write.
  859.       
  860.  
  861.        (26) jdisint
  862.            VOID jdisint(intno)
  863.            WORD intno;
  864.                  Disable interrupt number 'intno' on the 68901.
  865.       
  866.  
  867.        (27) jenabint
  868.            VOID jenabint(intno)
  869.            WORD intno;
  870.                  Enable interrupt number 'intno' on the 68901.
  871.       
  872.  
  873.        (28) giaccess
  874.            BYTE giaccess(data, regno)
  875.            BYTE data;
  876.            WORD regno;
  877.                  Read or write  a  register  on  the  sound  chip.
  878.                  'regno'  is  the  register number, logically ORed
  879.                  with:
  880.       
  881.                      $00 to read [well, ok, you don't
  882.                          /really/ OR with this...]
  883.                      $80 to write
  884.       
  885.                  'data' is a byte to write to the register.
  886.       
  887.                  Sound chip  registers  are  not  shadowed.   Pro-
  888.                  cedures  that change register values by reading a
  889.                  register, modifying a local copy of it, and writ-
  890.                  ing  the  result  back to the register, should be
  891.                  critical sections.  In particular, the BIOS (fre-
  892.                  quently)  updates  the  PORT  A register, and any
  893.                  code  that  read-modify-writes  PORT  A  must  be
  894.                  atomic.
  895.       
  896.  
  897.        (29) offgibit
  898.            VOID offgibit(bitno)
  899.            WORD bitno;
  900.                  Atomically set a bit in the PORT  A  register  to
  901.                  zero.
  902.       
  903.  
  904.        (30) ongibit
  905.            VOID ongibit(bitno)
  906.            WORD bitno;
  907.                  Atomically set a bit in the PORT  A  register  to
  908.                  one.
  909.       
  910.  
  911.        (31) xbtimer
  912.            VOID xbtimer(timer, control, data, vec)
  913.            WORD timer, control, data;
  914.            LONG vec;
  915.                  'timer'  is  the  timer  number  (0,  1,   2,   3
  916.                  corresponding  to  68901  timers  A, B, C and D).
  917.                  'control' is the  timer's  control-register  set-
  918.                  ting.   'data'  is a byte shoved into the timer's
  919.                  data register.  'vec' is a pointer to  an  inter-
  920.                  rupt handler.
  921.       
  922.                  Timers are allocated:
  923.       
  924.                      Timer   Usage
  925.                        A     Reserved for end-users and applications
  926.                        B     Reserved for graphics (hblank sync, etc.)
  927.                        C     System timer (200hz)
  928.                        D     RS-232 baud-rate control (this timer's
  929.                              interrupt vector is available to anyone).
  930.       
  931.       
  932.        (32) dosound
  933.            VOID dosound(ptr)
  934.            LONG ptr;
  935.                  Set sound daemon's "program  counter"  to  'ptr'.
  936.                  'ptr'  points  to  a set of commands organized as
  937.                  bytes.
  938.       
  939.                  Command numbers $00 through $0F take a  one  byte
  940.                  argument to be shoved into a sound chip register.
  941.                  (Command $00 shoves the  byte  into  register  0,
  942.                  command  1  shoves  the byte into register 1, and
  943.                  you get the idea...)
  944.       
  945.                  Command $80 takes a one byte  argument  which  is
  946.                  shoved into a temporary register.
  947.       
  948.                  Command $81 takes three one-byte arguments.   The
  949.                  first  argument  is  a  register  number to load,
  950.                  using the temp register.  The second argument  is
  951.                  a  2's  complement  value to be added to the temp
  952.                  register.  The third argument is the  termination
  953.                  value.  The instruction is executed (once on each
  954.                  update) until the temp register equals the termi-
  955.                  nation value.
  956.       
  957.                  Commands  $82  through  $FF   take   a   one-byte
  958.                  argument.   If the argument is zero, the sound is
  959.                  terminated.  Otherwise the argument reflects  the
  960.                  number  of system-timer ticks (at 50hz) until the
  961.                  next update.
  962.       
  963.  
  964.        (33) setprt
  965.            WORD setprt(config)
  966.            WORD config;
  967.                  Set/get printer configuration byte.  If  'config'
  968.                  is  -1  ($FFFF) return the current printer confi-
  969.                  guration byte.  Otherwise set the byte and return
  970.                  it's old value.
  971.       
  972.                  Bits currently defined are:
  973.       
  974.                       Bit#   When 0          When 1
  975.                       ----   -------------   ---------------
  976.                        0     Dot matrix      Daisy wheel
  977.                        1     Color device    Monochrome device
  978.                        2     Atari printer   "Epson" printer
  979.                        3     Draft mode      Final mode
  980.                        4     Parallel port   RS232 port
  981.                        5     Form-feed       Single sheet
  982.                        6             reserved
  983.                        7             reserved
  984.                        8             reserved
  985.                        9             reserved
  986.                        10            reserved
  987.                        11            reserved
  988.                        12            reserved
  989.                        13            reserved
  990.                        14            reserved
  991.                        15    Must be zero
  992.       
  993.       
  994.        (34) kbdvbase
  995.            LONG kbdvbase()
  996.                  Returns a pointer to the base of a structure:
  997.       
  998.                      struct kbdvecs {
  999.                          LONG midivec;       /* MIDI-input */
  1000.                          LONG vkbderr;       /* keyboard error */
  1001.                          LONG vmiderr;       /* MIDI error */
  1002.                          LONG statvec;       /* ikbd status packet */
  1003.                          LONG mousevec;      /* mouse packet */
  1004.                          LONG clockvec;      /* clock packet */
  1005.                          LONG joyvec;        /* joystick packet */
  1006.                          LONG midisys;       /* system MIDI vector */
  1007.                          LONG ikbdsys;       /* system IKBD vector */
  1008.                      };
  1009.       
  1010.                  'midivec' is initialized to point to a  buffering
  1011.                  routine in the BIOS.  D0.B will contain a charac-
  1012.                  ter read from the MIDI port.
  1013.       
  1014.                  'vkbderr' and 'vmiderr' are  called  whenever  an
  1015.                  overrun  condition is detected on the keyboard or
  1016.                  MIDI 6850s.  [Probably not  a  useful  vector  to
  1017.                  grab.]
  1018.       
  1019.                  'statvec', 'mousevec', 'clockvec',  and  'joyvec'
  1020.                  point to ikbd status, mouse, real-time clock, and
  1021.                  joystick packet handlers.   The  packet  handlers
  1022.                  are  passed  a  pointer to the packet received in
  1023.                  A0, and on the stack as a LONG.  GEM/GSX uses the
  1024.                  mouse  vector.   Handlers  should  return with an
  1025.                  RTS, and should not spend more than 1ms  handling
  1026.                  the interrupt.
  1027.       
  1028.                  The 'midisys' and 'ikbdsys'  vectors  are  called
  1029.                  when  characters are available on the appropriate
  1030.                  6850.  Initially they point to  default  routines
  1031.                  (the  MIDI  handler  indirects through 'midivec',
  1032.                  and the ikbd handler parses-out ikbd packets  and
  1033.                  calls the appropriate subsystem vectors).
  1034.       
  1035.  
  1036.        (35) kbrate
  1037.            WORD kbrate(initial, repeat)
  1038.            WORD initial, repeat;
  1039.                  Get/set the keyboard's  repeat  rate.   'initial'
  1040.                  governs  the  initial  delay  (before  key-repeat
  1041.                  starts).  'repeat'  governs  the  rate  at  which
  1042.                  key-repeats  are generated.  If a parameter is -1
  1043.                  ($FFFF) it is not changed.  Times  are  based  on
  1044.                  system ticks (50hz).
  1045.       
  1046.                  Returns the old key-repeat values, with 'initial'
  1047.                  in  the high byte of the low word and 'repeat' in
  1048.                  the low byte of the low word.
  1049.       
  1050.  
  1051.        (36) _prtblk
  1052.            VOID _prtblk()
  1053.                  Prtblk() primitive [see manual pages on PRTBLK].
  1054.       
  1055.  
  1056.        (37) vsync
  1057.            VOID vsync()
  1058.                  Waits until the next vertical-blank interrupt and
  1059.                  returns.    Useful   for  synchronizing  graphics
  1060.                  operations with vblank.
  1061.       
  1062.  
  1063.        (38) supexec
  1064.            VOID supexec(codeptr)
  1065.            LONG codeptr;
  1066.                  'codeptr' points to a piece of code, ending in an
  1067.                  RTS,  that  is  executed in supervisor mode.  The
  1068.                  code cannot perform BIOS or GEMDOS  calls.   This
  1069.                  function  is  meant  to  allow  programs  to hack
  1070.                  hardware and protected locations  without  having
  1071.                  to  fiddle  with  GEMDOS  get/set supervisor mode
  1072.                  call.
  1073.       
  1074.  
  1075.        (39) puntaes
  1076.            VOID puntaes()
  1077.                  Throws away the AES, freeing  up  any  memory  it
  1078.                  used.   If  the AES is still resident, it will be
  1079.                  discarded and the system will reboot.  If the AES
  1080.                  is not resident (if it was discarded earlier) the
  1081.                  function will return.
  1082.       
  1083.                  There is NO way to throw away the AES and  return
  1084.                  --  the  reboot MUST be performed.  [Ok, ok -- we
  1085.                  know this is a lose.]
  1086.       
  1087.       
  1088.                              ~~~OOOO~~~      
  1089.       
  1090.  
  1091.                           Terminal Escapes     
  1092.                           ----------------
  1093.       
  1094.                       CONOUT Escape Sequences
  1095.       
  1096.       
  1097.       These are the escape  functions  interpreted  by  the  BIOS'
  1098.       conout()  function.   For the most part they emulate a VT-52
  1099.       terminal [that's the easy one to do].  There are  extensions
  1100.       to  hack screen colors, control screen wrap, and a few other
  1101.       simple functions.
  1102.       
  1103.       ESC A
  1104.       Cursor Up
  1105.            This sequence moves the cursor up  one  line.   If  the
  1106.            cursor  is  already on the top line of the screen, this
  1107.            sequence has no effect.
  1108.       
  1109.       ESC B
  1110.       Cursor Down
  1111.            This moves the cursor down one line.  If the cursor  is
  1112.            already  on  the  last  line of the screen, this escape
  1113.            sequence has no effect.
  1114.       
  1115.       ESC C
  1116.       Cursor Forward
  1117.            This moves the cursor one position to  the  right.   If
  1118.            this  function  would  move  the cursor off the screen,
  1119.            this sequence has no effect.
  1120.       
  1121.       ESC D
  1122.       Cursor Backward
  1123.            This move the cursor one position to the left.  This is
  1124.            a  non-  destructive  move  because  the character over
  1125.            which the cursor now rests is not replaced by a  blank.
  1126.            If  the  cursor  is  already  in  column O, this escape
  1127.            sequence has no effect.
  1128.       
  1129.       ESC E
  1130.       Clear Screen (and Home Cursor)
  1131.            This moves the cursor to  column  O,  row  I  (the  top
  1132.            left-hand corner of the screen), and clears all charac-
  1133.            ters from the screen.
  1134.       
  1135.       ESC H
  1136.       Home Cursor
  1137.            This move the cursor to column O, row O.  The screen is
  1138.            NOT cleared.
  1139.       
  1140.       ESC I
  1141.       Reverse Index
  1142.            Moves the cursor to the same horizontal position on the
  1143.            preceding  lines.   If the cursor is on the top line, a
  1144.            scroll down is performed.
  1145.       
  1146.       ESC J
  1147.       Erase to End of Page
  1148.            Erases all the information from cursor (including  cur-
  1149.            sor position) to the end of the page.
  1150.       
  1151.       ESC K
  1152.       Clear to End of Line
  1153.            This sequence clears the line from the  current  cursor
  1154.            position to the end of the line.
  1155.       
  1156.       ESC L
  1157.       Insert Line
  1158.            Inserts a new blank line by moving the line that cursor
  1159.            is  on,  end all following lines, down one line.  Then,
  1160.            the cursor is moved to the beginning of the  new  blank
  1161.            line.
  1162.       
  1163.       ESC M
  1164.       Delete Line
  1165.            Deletes the contents of the line that the cursor is on,
  1166.            places  the  cursor at the beginning of the line, moves
  1167.            all the following lines up one line, and adds  a  blank
  1168.            line at the bottom.
  1169.       
  1170.       ESC Y
  1171.       Position Cursor
  1172.            The two characters that follow the "Y" specify the  row
  1173.            and  column  to  which  the cursor is to be moved.  The
  1174.            first character specifies the row, the second specifies
  1175.            the colum.  Rows and columns number from 1 up.
  1176.       
  1177.       ESC b
  1178.       Set Foreground Color
  1179.            The Foreground Color is the color in which the  charac-
  1180.            ter is displayed.
  1181.       
  1182.            Escape-b must be followed by a color selection  charac-
  1183.            ter.  Only the four least significant bits of the color
  1184.            character are used:
  1185.       
  1186.            Bit Pattern of Control Byte:
  1187.       
  1188.                   7     6     5     4     3     2     1     0
  1189.                +-----+-----+-----+-----+-----+-----+-----+-----+
  1190.                |     |     |     |     |                       |
  1191.                |  X  |  X  |  X  |  X  |    color index        |
  1192.                |     |     |     |     |                       |
  1193.                +-----+-----+-----+-----+-----+-----+-----+-----+
  1194.                (X = "don't care")
  1195.       
  1196.       ESC c
  1197.       Set Background Color
  1198.            This function selects Background Color,  the  color  of
  1199.            the cell that contains the characters.
  1200.       
  1201.            Escape-c must be followed by a color selection  charac-
  1202.            ter.  Only the four least significant bits of the color
  1203.            character are used.  (See diagram for ESC-b function)
  1204.       
  1205.       ESC d
  1206.       Erase Beginning of Display
  1207.            This sequence erases from beginning of the  display  to
  1208.            the  cursor  position.   The  cursor position is erased
  1209.            also.
  1210.       
  1211.       ESC e
  1212.       Enable Cursor
  1213.            This sequence causes the cursor to be  invisible.   The
  1214.            cursor  may  still be moved about on the display, using
  1215.            escape sequence defined in this appendix.
  1216.       
  1217.       ESC f
  1218.       Disable Cursor
  1219.            This sequence causes the cursor to be  invisible.   The
  1220.            cursor  may  still be moved about on the display, using
  1221.            escape sequences defined in this appendix.
  1222.       
  1223.       ESC j
  1224.       Save Cursor Position
  1225.            This sequence preserves the  current  cursor  position.
  1226.            You  can  restore  the  cursor  to the previously saved
  1227.            position with ESC-k.
  1228.       
  1229.       ESC k
  1230.       Restore Cursor Position
  1231.            This sequence restores the cursor to a previously saved
  1232.            position.  If you use this sequence without having pre-
  1233.            viously saved the cursor position, then the  cursor  is
  1234.            moved to the home position, the top left-hand corner of
  1235.            the screen.
  1236.       
  1237.       ESC l
  1238.       Erase Entire Line
  1239.            This sequence erases an entire line and moves the  cur-
  1240.            sor to the leftmost column.
  1241.       
  1242.       ESC o
  1243.       Erase Beginning of Line
  1244.            Erases from the beginning of the line to the cursor and
  1245.            includes the cursor position.
  1246.       
  1247.       ESC p
  1248.       Enter Reverse Video Mode
  1249.            Enters the reverse video mode so  that  characters  are
  1250.            displayed  as  background  color  characters on a fore-
  1251.            ground colored cell.
  1252.       
  1253.       ESC q
  1254.       Exit Reverse Video Mode
  1255.            Exits the reverse video mode.
  1256.       
  1257.       ESC v
  1258.       Wrap at End of Line
  1259.            This sequence causes the first character past the  last
  1260.            displayable  position  on  a  line  to be automatically
  1261.            placed in the first  character  position  on  the  next
  1262.            line.  The page scrolls up if necessary.
  1263.       
  1264.       ESC w
  1265.       Discard at End of Line
  1266.            Following invocation of this sequence, after  the  last
  1267.            displayable  character  on a line has been reached, the
  1268.            characters overprint.  Therefore, only the last charac-
  1269.            ter received is displayed in the last column position.
  1270.  
  1271.       
  1272.                                 ~~~OOOO~~~
  1273.  
  1274.  
  1275.       Prtblk()              August 26, 1985                     
  1276.       
  1277.       
  1278.                        This page unintentionally
  1279.                               left blank.
  1280.       
  1281.       
  1282.                   Documentation on prtblk() goes HERE!
  1283.       
  1284.       
  1285.                                 ~~~OOOO~~~
  1286.  
  1287.  
  1288.                   Traps, Interrupts and Interrupt Vectors
  1289.                   ---------------------------------------    
  1290.       
  1291.       The ST makes use of four of the sixteen  TRAP  vectors  pro-
  1292.       vided  by  the  68000.   All  other  traps are available for
  1293.       applications.
  1294.       
  1295.            Trap   Use
  1296.            ----   ----
  1297.             0     (none)
  1298.             1     GEMDOS interface
  1299.             2     DOS extensions (GEM, GSX)
  1300.             3     (none)
  1301.             4     (none)
  1302.             5     (none)
  1303.             6     (none)
  1304.             7     (none)
  1305.             8     (none)
  1306.             9     (none)
  1307.             10    (none)
  1308.             11    (none)
  1309.             12    (none)
  1310.             13    BIOS
  1311.             14    Atari BIOS extensions
  1312.             15    (none)
  1313.       
  1314.       
  1315.       68901 interrupts are based at $100.  The  sixteen  longwords
  1316.       at this location are bound by the hardware to:
  1317.       
  1318.            Vector    Function
  1319.             $100     (disabled) Parallel port int.
  1320.             $104     (disabled) RS232 Carrier Detect
  1321.             $108     (disabled) RS232 Clear-To-Send
  1322.             $10c     (disabled)
  1323.             $110     (disabled)
  1324.             $114     200hz System clock
  1325.             $118     Keyboard/MIDI [6850]
  1326.             $11c     (disabled) Polled FDC/HDC
  1327.             $120     HSync (initially disabled)
  1328.             $124     RS232 transmit error
  1329.             $128     RS232 transmit buffer emtpy
  1330.             $12c     RS232 receive error
  1331.             $130     RS232 receive buffer full
  1332.             $134     (disabled)
  1333.             $138     (disabled) RS232 ring indicator
  1334.             $13c     (disabled) Polled monitor type
  1335.       
  1336.       
  1337.       The divide-by-zero vector is pointed at an RTE.
  1338.       
  1339.       All other traps (Bus Error, et al) are pointed at a  handler
  1340.       that dumps the processor state and attempts to terminate the
  1341.       current process.  [See: System Initialization]
  1342.       
  1343.       The Line 1010 ("Line Aye") vector is used as a short-circuit
  1344.       around  the  VDI  to  the ST's graphics primitives.  It is a
  1345.       powerful and useful interface; see the `Line A' document for
  1346.       further information.
  1347.       
  1348.       The Line 1111 ("Line Eff")  trap  is  currently  being  used
  1349.       internally  to  the  system.  If you fiddle with this vector
  1350.       the AES will break.
  1351.       
  1352.       The FDC/HDC interrupt may be enabled by a hard  disk  device
  1353.       driver.   The floppy disk code, however, assumes this inter-
  1354.       rupt is disabled (it busy-waits on the input  bit's  state).
  1355.       It  is  the responsibility of other drivers in the system to
  1356.       ensure that, when the  floppy  disk  read/write/format  code
  1357.       gets control, the FDC/HDC interrupt is disabled.
  1358.       
  1359.       The processor's normal interrupt priority level is 3.   This
  1360.       is  to  prevent  HBLANK (autovector level 2) interrupts from
  1361.       occurring on every scanline.  [It would eat about 10%  of  a
  1362.       system  running  in a color graphics mode, or about 22% of a
  1363.       system running in monochrome.   Yuck.]  The  default  HBLANK
  1364.       interrupt handler modifies the interrupted process' IPL to 3
  1365.       and performs an RTE.  This is to  discourage  programs  from
  1366.       using IPL 0 -- to use HBLANK, use an IPL of 1.
  1367.       
  1368.       To prevent "jittering" in programs that change screen colors
  1369.       on  the  fly,  using the HBLANK and HSYNC interrupt vectors,
  1370.       the following hack will keep the  system  intact  and  still
  1371.       yield a solid display:
  1372.       
  1373.          [1] Re-vector the keyboard/MIDI interrupt  to  a  routine
  1374.              that  lowers  the IPL to 5 and then jumps through the
  1375.              original vector.
  1376.       
  1377.          [2] During the "critical"  section  of  the  screen,  re-
  1378.              vector  the  200hz  system  clock interrupt vector to
  1379.              point to a routine  that  increments  a  counter  and
  1380.              RTEs.   The counter keeps track of the number of sys-
  1381.              tem ticks that occur during the critical section.
  1382.       
  1383.          [3] After the critical section, block interrupts (at  IPL
  1384.              6)  and call the sytem clock handler (JMP through the
  1385.              interrupt vector, with a fake SR and  return  address
  1386.              on  the  stack)  the number of times indicated by the
  1387.              counter.
  1388.       
  1389.       
  1390.                                 ~~~OOOO~~~
  1391.  
  1392.  
  1393.                              System Variables
  1394.                              ----------------      
  1395.       
  1396.          This is a list of variables in the ST BIOS that have been
  1397.          "cast  in  concrete".   Their  locations  and meanings in
  1398.          future revisions of the ST BIOS  are  guarenteed  not  to
  1399.          change.
  1400.       
  1401.          Any other variables in RAM, routines in the ROM, or  vec-
  1402.          tors  below  $400 that are not documented here are almost
  1403.          certain to change.  It is  important  not  to  depend  on
  1404.          undocumented variables or ROM locations.
  1405.       
  1406.          etv_timer (long) $400
  1407.              Timer handoff vector (logical vector $100).  See GEM-
  1408.              DOS documentation.
  1409.       
  1410.          etv_critic (long) $404
  1411.              Critical error handoff vector (logical vector  $101).
  1412.              See GEMDOS documentation.
  1413.       
  1414.          etv_term (long) $408
  1415.              Process-terminate  handoff  vector  (logical   vector
  1416.              $102).  See GEMDOS documentation.
  1417.       
  1418.          etv_xtra (longs) $40c
  1419.              Space for logical vectors $103 through $107).
  1420.       
  1421.          memvalid (long) $420
  1422.              Contains the magic number $752019F3, which  (together
  1423.              with  'memval2') validates 'memcntlr' and indicates a
  1424.              successful coldstart.
  1425.       
  1426.          memcntlr (byte) $424
  1427.              Contains memory controller configuration nibble  (the
  1428.              low  nibble).   For  the full story, see the hardware
  1429.              manual.  Some popular values are:
  1430.       
  1431.                  Memory size     Value
  1432.                  128K            0
  1433.                  512K            4
  1434.                  256K (2 banks)  0
  1435.                  1MB (2 banks)   5
  1436.       
  1437.       
  1438.          resvalid (long) $426
  1439.              If 'resvalid' is the magic number $31415926 on system
  1440.              RESET, the system will jump though 'resvector'.
  1441.       
  1442.          resvector (long) $42a
  1443.              System-RESET bailout vector, valid if 'resvalid' is a
  1444.              magic  number.  Called early-on in system initializa-
  1445.              tion (before /any/ hardware registers, including  the
  1446.              memory  controller  configuration register, have been
  1447.              touched).  A return address will be loaded  into  A6.
  1448.              Both stack pointers will contain garbage.
  1449.       
  1450.          phystop (long) $42e
  1451.              Physical top of RAM.  Contains a pointer to the first
  1452.              unusable byte (i.e. $80000 on a 512K machine).
  1453.       
  1454.          _membot (long) $432
  1455.              Bottom of available memory.  The 'getmpb' BIOS  func-
  1456.              tion uses this value as the start of the GEMDOS TPA.
  1457.       
  1458.          _memtop (long) $436
  1459.              Top of available memory.  The 'getmpb' BIOS  function
  1460.              uses this value as the end of the GEMDOS TPA.
  1461.       
  1462.          memval2 (long) $43a
  1463.              Contains the magic number $237698AA  which  (together
  1464.              with 'memvalid') validates 'memcntlr' and indicates a
  1465.              successful coldstart.
  1466.       
  1467.          flock (word) $43e
  1468.              Used to lock  usage  of  the  DMA  chip.   Should  be
  1469.              nonzero  to ensure that the OS does not touch the DMA
  1470.              chip registers during vertical blank.   Device-driver
  1471.              writers  TAKE  NOTE: this variable MUST be nonzero in
  1472.              order to make use of the DMA bus.
  1473.       
  1474.          seekrate (word) $440
  1475.              Default floppy seek rate.  Bits zero and one  contain
  1476.              the default floppy disk seek rate for both drives:
  1477.       
  1478.                  00      6ms
  1479.                  01      12ms
  1480.                  10      2ms
  1481.                  11      3ms [default]
  1482.       
  1483.          _timr_ms (word) $442
  1484.              System timer calibration (in ms).  Should be $14  (20
  1485.              decimal), since the timer handoff vector is called at
  1486.              50hz.  Returned  by  BIOS  function  '_tickcal',  and
  1487.              passed on the stack to the timer handoff vector.
  1488.       
  1489.          _fverify (word) $444
  1490.              Floppy verify flag.   When  nonzero,  all  writes  to
  1491.              floppies  are  read-verified.   When  zero, no write-
  1492.              verifies  take  place.   The  default  state   (after
  1493.              system-reset) is to verify.
  1494.       
  1495.          _bootdev (word) $446
  1496.              Contains the device  number  the  system  was  booted
  1497.              from.   The BIOS constructs an enviroment string from
  1498.              this variable before bringing up the desktop.
  1499.       
  1500.          palmode (word) $448
  1501.              When nonzero, indicates the system is  in  PAL  (50hz
  1502.              video)  mode.   When zero, indicates the system is in
  1503.              NTSC (60hz video) mode.
  1504.       
  1505.          defshiftmd (byte) $44a
  1506.              Default video resolution.  If the system is forced to
  1507.              change  from  monochrome  mode to a color resolution,
  1508.              'defshiftmd' contains the resolution the system  will
  1509.              switch to.
  1510.       
  1511.          sshiftmd (word) $44c
  1512.              Contains shadow for 'shiftmd' hardware register:
  1513.       
  1514.                  0       320x200x4 (low resolution)
  1515.                  1       640x200x2 (medium rez)
  1516.                  2       640x400x1 (high rez / "monochrome")
  1517.       
  1518.          _v_bas_ad (long) $44e
  1519.              Pointer to base of screen memory.  Always on  a  512-
  1520.              byte  boundary.   Always  points to 32K of contiguous
  1521.              memory.
  1522.       
  1523.          vblsem (word) $452
  1524.              Semaphore to enforce mutual  exclusion  in  vertical-
  1525.              blank  interrupt  handler.   Should  be '1' to enable
  1526.              vblank processing,
  1527.       
  1528.          nvbls (word) $454
  1529.              Number of longwords that '_vblqueue' points to.   (On
  1530.              RESET, defaults to 8).
  1531.       
  1532.          _vblqueue (long) $456
  1533.              Pointer to a vector of pointers to vblank handlers.
  1534.       
  1535.          colorptr (long) $45a
  1536.              Pointer to a vector of 16  words  to  load  into  the
  1537.              hardware  palette  registers  on the next vblank.  If
  1538.              NULL, the palettes are  not  loaded.   'colorptr'  is
  1539.              zeroed after the palettes are loaded.
  1540.       
  1541.          screenpt (long) $45e
  1542.              Pointer to the base of screen memory, to be setup  on
  1543.              the  next  vblank.   If  NULL, the screen base is not
  1544.              changed.
  1545.       
  1546.          _vbclock (long) $462
  1547.              Count of vertical-blank interrupts.
  1548.       
  1549.          _frclock (long) $466
  1550.              Count of vertical-blank  interrupts  that  were  pro-
  1551.              cessed (not blocked by 'vblsem').
  1552.       
  1553.          hdv_init (long) $46a
  1554.              Vector to hard disk initialization.  NULL if unused.
  1555.       
  1556.          swv_vec (long) $46e
  1557.              The system follows this  vector  when  it  detects  a
  1558.              transition  on  the "monochrome monitor detect" input
  1559.              (from low to high  rez,  or  visa-versa).   'swv_vec'
  1560.              initially  points to the system reset handler; there-
  1561.              fore the system will reset if the user changes  moni-
  1562.              tors.
  1563.       
  1564.          hdv_bpb (long) $472
  1565.              Vector to routine to return a hard disk's Bios Param-
  1566.              eter  Block  (BPB).   Same calling conventions as the
  1567.              BIOS function for GETBPB.  NULL if unused.
  1568.       
  1569.          hdv_rw (long) $476
  1570.              Vector to routine to read or write on  a  hard  disk.
  1571.              Same  calling  conventions  as  the BIOS function for
  1572.              RWABS.  NULL if unused.
  1573.       
  1574.          hdv_boot (long) $47a
  1575.              Vector to routine to boot from hard  disk.   NULL  if
  1576.              unused.
  1577.       
  1578.          hdv_mediach (long) $47e
  1579.              Vector to routine  to  return  a  hard  disk's  media
  1580.              change  mode.   Same  as  BIOS  binding for floppies.
  1581.              NULL if unused.
  1582.       
  1583.          _cmdload (word) $482
  1584.              When nonzero an attempt is made to load  and  execute
  1585.              COMMAND.PRG  from  the boot device.  (Load a shell or
  1586.              an application in place of the desktop).  Can be  set
  1587.              to nonzero by a boot sector.
  1588.       
  1589.          conterm (byte) $484
  1590.              Contains attribute bits for the console system:
  1591.       
  1592.                  Bit     Function
  1593.                  0       nonzero: enable bell when ^G is written to CON:
  1594.                  1       nonzero: enable key-repeat
  1595.                  2       nonzero: enable key-click
  1596.                  3       nonzero: on BIOS conin() function, return the
  1597.                                   current value of 'kbshift' in bits
  1598.                                   24..31 of D0.L.
  1599.                          zero:    leave bits 24..31 alone...
  1600.       
  1601.          themd (long) $48e
  1602.              Filled in by the BIOS on a 'getmpb'  call;  indicates
  1603.              to GEMDOS the limits of the TPA.  The structure is:
  1604.       
  1605.                  struct MD
  1606.                  {
  1607.                          MD      *m_link;        /* ->next MD [NULL] */
  1608.                          long    m_start;        /* start of TPA */
  1609.                          long    m_length;       /* size of TPA (bytes) */
  1610.                          PD      *m_own;         /* ->MD's owner [NULL] */
  1611.                  } ;
  1612.       
  1613.              The structure may NOT be changed once GEMDOS has been
  1614.              initialized.   In  addition, there may be only ONE of
  1615.              these suckers (you can't use the  'm_link'  field  in
  1616.              the  first MD).  Someday these (with a better GEMDOS)
  1617.              these limitations may be lifted.
  1618.       
  1619.          savptr (long) $4a2
  1620.              Pointer to register save area for BIOS functions.
  1621.       
  1622.          _nflops (word) $4a6
  1623.              Number of floppy disks actually attached to the  sys-
  1624.              tem (0, 1, or 2).
  1625.       
  1626.          sav_context (long) $4ae
  1627.              Pointer to saved  processor  context  (more  on  this
  1628.              later).
  1629.       
  1630.          _bufl (long) $4b4
  1631.              Two (GEMDOS) buffer-list  headers.   The  first  list
  1632.              buffers data sectors, the second list buffers FAT and
  1633.              directory sectors.  Each of these pointers points  to
  1634.              a BCB (Buffer Control Block), that looks like:
  1635.       
  1636.       
  1637.                  struct BCB
  1638.                  {
  1639.                          BCB     *b_link;        /* next BCB */
  1640.                          int     b_bufdrv;       /* drive#, or -1 */
  1641.                          int     b_buftyp;       /* buffer type */
  1642.                          int     b_bufrec;       /* record# cached here */
  1643.                          int     b_dirty;        /* dirty flag */
  1644.                          DMD     *b_dm;          /* -> Drive Media Descriptor */
  1645.                          char    *b_bufr;        /* -> buffer itself */
  1646.                  } ;
  1647.       
  1648.          _hz_200 (long) $4bc
  1649.              Raw 200hz system timer tick.  Used to  divide-by-four
  1650.              for a 50hz system timer.
  1651.       
  1652.          the_env (byte[4]) $4be
  1653.              The default enviroment string.  Four bytes of $00....
  1654.       
  1655.          _drvbits (long) $4c4
  1656.              32-bit vector, returned by the "DRIVEMAP" BIOS  func-
  1657.              tion (#10), of "live" block devices.  If any floppies
  1658.              are attached, this value is 3.
  1659.       
  1660.          _dskbufp (long) $4c6
  1661.              Points to a 1024-byte disk buffer  somewhere  in  the
  1662.              system's  BSS.   The buffer is ALSO used for some GSX
  1663.              graphics operations, and should not be used by inter-
  1664.              rupt routines.
  1665.       
  1666.          _prt_cnt (word) $4ee
  1667.              Initialized to -1.  Pressing the ALT-HELP key  incre-
  1668.              ments this.  The screen dump code checks for $0000 to
  1669.              start imaging the screen to the printer,  and  checks
  1670.              for nonzero to abort the screen print.
  1671.       
  1672.          _sysbase (long) $4f2
  1673.              Points to the base of the OS (in ROM or RAM).
  1674.       
  1675.          _shell_p (long) $4f6
  1676.              Points to shell-specific context.
  1677.       
  1678.          end_os (long) $4fa
  1679.              Points just past the last byte of low RAM used by the
  1680.              operating  system.   This is used as the start of the
  1681.              TPA (end_os is copied into _membot).
  1682.       
  1683.          exec_os (long) $4fe
  1684.              This points to the shell that gets exec'd by the BIOS
  1685.              after  system  initialization  is complete.  Normally
  1686.              this points to the first byte of the AES'  text  seg-
  1687.              ment.
  1688.       
  1689.       
  1690.                              ~~~OOOO~~~      
  1691.  
  1692.  
  1693.                       POST MORTEM INFORMATION
  1694.                       -----------------------
  1695.       
  1696.          If a diagnostic cartridge is not inserted,  all  "unused"
  1697.          interrupt  vectors  are  pointed to a handler in the BIOS
  1698.          that saves the  processor's  state  in  low  memory  (see
  1699.          below)  and  displays  a number of icons in the middle of
  1700.          the screen.  The handler attempts to restart  the  system
  1701.          after  the  crash -- it is not always (honestly: it isn't
  1702.          very often) successful.
  1703.       
  1704.          The exact number of icons represents the  exception  that
  1705.          occurred (2 for bus error, 3 for address error, and so on
  1706.          -- see the `Exception Processing' section in the Motorola
  1707.          68000 manual).
  1708.       
  1709.          The processor state is saved in an area of memory that is
  1710.          NOT  touched by a system reset.  Therefore it is possible
  1711.          to examine a post-mortem dump after resetting the  system
  1712.          to reboot.
  1713.       
  1714.              *+
  1715.              *  Post-mortem dump area;
  1716.              *  processor state saved here on uncaught exception:
  1717.              *
  1718.              *-
  1719.              proc_lives      equ     $380    ; $12345678 iff valid
  1720.              proc_dregs      equ     $384    ; saved D0-D7
  1721.              proc_aregs      equ     $3a4    ; saved A0-A6, supervisor A7 (SSP)
  1722.              proc_enum       equ     $3c4    ; first byte is exception #
  1723.              proc_usp        equ     $3c8    ; saved user A7
  1724.              proc_stk        equ     $3cc    ; sixteen words popped from SSP
  1725.       
  1726.       
  1727.          If the longword at $380 is the  magic  number  $12345678,
  1728.          then the following information is valid (unless it's been
  1729.          stepped on by another crash).
  1730.       
  1731.          D0-D7, A0-A6, and the supervisor A7 are copied  to  loca-
  1732.          tions  $384  to  $3c0.   The  exception number (2 for bus
  1733.          error, etc.) is recorded in the byte at $3c4.   The  user
  1734.          A7  is  copied  to  $3c8.  The first sixteen words at the
  1735.          supervisor A7 are copied to the sixteen words starting at
  1736.          $3cc.
  1737.       
  1738.       
  1739.                                 ~~~OOOO~~~
  1740.  
  1741.  
  1742.              Getting Into and Out Of Supervisor Mode in GEMDOS
  1743.              -------------------------------------------------
  1744.  
  1745.          DRI hasn't bothered to document  this  function  yet,  so
  1746.          ....
  1747.       
  1748.          Yes, there IS a way to get into (or  out  of)  supervisor
  1749.          mode  in  GEMDOS.   While you read the following descrip-
  1750.          tion, please bear in mind that the original intent was to
  1751.          provide a binding usable at the C level.  It is clumsy to
  1752.          use from assembly language.
  1753.       
  1754.          The function is Trap 1, number 32 (hex  $20).   It  wears
  1755.          three hats:
  1756.       
  1757.              LONG _super(stack)
  1758.              LONG stack;
  1759.       
  1760.          If 'stack' is -1 ($FFFFFFFF), then the  function  returns
  1761.          (in D0.L) either a 0 (indicating that the processor is in
  1762.          user mode) or a 1 (indicating that the  processor  is  in
  1763.          supervisor mode).
  1764.       
  1765.          If the function is called when the processor is  in  user
  1766.          mode, GEMDOS will return with the processor in supervisor
  1767.          mode.  The old value of  the  supervisor  stack  will  be
  1768.          returned  in D0.L.  If 'stack' was NULL ($00000000), then
  1769.          the supervisor stack will be the same as the  user  stack
  1770.          before  the call.  Otherwise the supervisor stack will be
  1771.          set to 'stack'.
  1772.       
  1773.          If the function is called when the processor is in super-
  1774.          visor mode, GEMDOS will return with the processor in user
  1775.          mode.  'stack' should be  the  value  of  the  supervisor
  1776.          stack  that  was  returned by the first call to the func-
  1777.          tion.
  1778.       
  1779.          The old value  of  the  supervisor  stack  MUST  restored
  1780.          before  the  process  terminates.   (Failure to do so may
  1781.          result in a crash).
  1782.       
  1783.          An example of how to use it from C:
  1784.       
  1785.              superstuff()
  1786.              {
  1787.                  long save_ssp;
  1788.                  long trap1();
  1789.       
  1790.                  /*
  1791.                   * Get into supervisor mode:
  1792.                   */
  1793.                  save_ssp = trap1(0x20, 0L);
  1794.       
  1795.                  ... do lots of supervisor stuff ....
  1796.       
  1797.                  /*
  1798.                   * Get out of supervisor mode,
  1799.                   * restore old supervisor stack:
  1800.                   */
  1801.                  trap1(0x20, save_ssp);
  1802.              }
  1803.       
  1804.       
  1805.          And from assembly:
  1806.       
  1807.              *+
  1808.              *  superstuff - play around in supervisor mode
  1809.              *
  1810.              *-
  1811.              superstuff:
  1812.                      .
  1813.                      .
  1814.                      .  do user stuff
  1815.                      .
  1816.       
  1817.                      clr.l   -(sp)                   ; we want our own stack
  1818.                      move.w  #$20,-(sp)              ; get/set supervisor mode
  1819.                      trap    #1                      ; (do it)
  1820.                      addq    #6,sp                   ; (clean up)
  1821.                      move.l  d0,save_ssp             ; save old SSP
  1822.       
  1823.                      .
  1824.                      .
  1825.                      .  do supervisor stuff
  1826.                      .
  1827.                      .
  1828.       
  1829.                      move.l  save_ssp,-(sp)          ; push old SSP
  1830.                      move.w  #$20,-(sp)              ; get/set supervisor mode
  1831.                      trap    #1                      ; (do it)
  1832.                      addq    #6,sp                   ; (clean up)
  1833.       
  1834.                      .
  1835.                      .
  1836.                      .  do user stuff
  1837.                      .
  1838.       
  1839.       
  1840.       
  1841.                                 ~~~OOOO~~~
  1842.  
  1843.  
  1844.                          GEMDOS Relocation Format
  1845.                          ------------------------
  1846.                      (Clarification to GEMDOS manual)
  1847.       
  1848.          This is the  REAL  GEMDOS  fixup  bytestream  format,  as
  1849.          implemented  by  the  function  xpgmld()  in  GEMDOS  (as
  1850.          opposed to what is documented in the GEMDOS manual):
  1851.       
  1852.              $00             no more relocation information
  1853.              $01             add $FE to the dot
  1854.              $02..$FF        add N to the dot, and fixup the longword there
  1855.       
  1856.          So, to fixup a longword $100 bytes from the  current  one
  1857.          (the dot), RELMOD would generate:
  1858.       
  1859.                      $01 $02
  1860.       
  1861.          [note that only longwords can be fixed up, and that  they
  1862.          must be on word boundaries.]
  1863.       
  1864.       
  1865.                                 ~~~OOOO~~~
  1866.  
  1867.  
  1868.                               Error Handling
  1869.                               --------------
  1870.       
  1871.          Error numbers are returned by certain BIOS and most  GEM-
  1872.          DOS  functions.   Note  that some GEMDOS functions return
  1873.          WORD error numbers instead of LONG ones  (that  is,  bits
  1874.          16..31 of D0.L are garbage).  Someday DRI will get around
  1875.          to fixing these ....
  1876.       
  1877.          [Describe  critical-error  handler  calling  conventions,
  1878.          whenever DRI gets around to defining them so they're use-
  1879.          ful.]
  1880.       
  1881.          0 (OK)
  1882.              Successful action (the anti-error).
  1883.       
  1884.          -1 (ERROR)
  1885.              All-purpose error.
  1886.       
  1887.          -2 (DRIVE_NOT_READY)
  1888.              Device was not ready, or was  not  attached,  or  has
  1889.              been busy for a long time.
  1890.       
  1891.          -3 (UNKNOWN_CMD)
  1892.              Device didn't know about a command.
  1893.       
  1894.          -4 (CRC_ERROR)
  1895.              Soft error while reading a sector.
  1896.       
  1897.          -5 (BAD_REQUEST)
  1898.              Device couldn't handle a command (the  command  might
  1899.              be  valid in other contexts).  Command parameters may
  1900.              be bad.
  1901.       
  1902.          -6 (SEEK_ERROR)
  1903.              Drive couldn't seek.
  1904.       
  1905.          -7 (UNKNOWN_MEDIA)
  1906.              Attempt to read foriegn media (usually means  a  cor-
  1907.              rupted or zero boot sector).
  1908.       
  1909.          -8 (SECTOR_NOT_FOUND)
  1910.              Sector could not be located.
  1911.       
  1912.          -9 (NO_PAPER)
  1913.              Printer is out of paper (this cannot happen on disks,
  1914.              right?)
  1915.       
  1916.          -10 (WRITE_FAULT)
  1917.              Failure on a write operation.
  1918.       
  1919.          -11 (READ_FAULT)
  1920.              Failure on a read operation.
  1921.       
  1922.          -12 (GENERAL_MISHAP)
  1923.              Reserved for future catastrophes.  [This seems to  be
  1924.              a useless error right now.]
  1925.       
  1926.          -13 (WRITE_PROTECT)
  1927.              Attempt to write  on  write-protected  or  write-only
  1928.              media.
  1929.       
  1930.          -14 (MEDIA_CHANGE)
  1931.              Media changed since last write -- the operation (read
  1932.              or  write)  did NOT take place.  (This is more a mes-
  1933.              sage to the file system than a real error).
  1934.       
  1935.          -15 (UNKNOWN_DEVICE)
  1936.              Operation specified a device the  BIOS  doesn't  know
  1937.              anything about.
  1938.       
  1939.          -16 (BAD_SECTORS)
  1940.              Format operation succeeded (for the  most  part)  but
  1941.              yielded bad sectors.
  1942.       
  1943.          -17 (INSERT_DISK)
  1944.              Ask user to insert a disk (this is more a message  to
  1945.              the  shell  --  GEM  or  COMMAND.PRG  --  to  start a
  1946.              dialouge with the user).
  1947.       
  1948.       
  1949.                              ~~~OOOO~~~      
  1950.  
  1951.                          Cartridge Support
  1952.                          -----------------      
  1953.       
  1954.          There are two kinds of  cartridges.   'Application'  car-
  1955.          tridges are recognized by GEM and the desktop.  'Diagnos-
  1956.          tic' cartridges are  executed  almost  immediately  after
  1957.          system  reset (before the 68000 touches any RAM), and may
  1958.          take over the entire system.
  1959.       
  1960.          The ST hardware maps cartridge space  to  a  128K  region
  1961.          starting  at $FA0000, extending to $FBFFFF.  The longword
  1962.          at $FA0000 has special meaning to the OS.  It  should  be
  1963.          one of the following:
  1964.                  $FA52255F indicates that a  diagnostic  cartridge
  1965.                      is inserted.
  1966.                  $ABCDEF42 indicates that an application cartridge
  1967.                      is inserted.
  1968.                  anything else is ignored.
  1969.       
  1970.          On system RESET, if a diagnostic  cartridge  is  inserted
  1971.          the   OS  will  (almost  immediately)  jump  to  location
  1972.          $FA0004.  A6 will contain a return  address  (should  the
  1973.          cartridge  ever  wish to continue with system initializa-
  1974.          tion).  The stack pointer will be garbage.  Most  of  the
  1975.          ST's  hardware registers will not have been touched.  The
  1976.          most significant of these registers is  the  memory  con-
  1977.          troller  --  the  diagnostic cartridge is responsible for
  1978.          sizing memory and initializing the memory controller.
  1979.       
  1980.          Application  cartridges   should   provide   'application
  1981.          header'  at  location  $FA0004 (immediately following the
  1982.          magic longword).  An application header contains informa-
  1983.          tion  about  an  application  in  ROM.   There may be any
  1984.          number of applications in a cartridge.
  1985.       
  1986.       
  1987.                      CARTRIDGE APPLICATION HEADER
  1988.                      +-----------------------+
  1989.                      |       CA_NEXT         | 0   ->next header
  1990.                      |                       |
  1991.                      +-----------------------+
  1992.                      |       CA_INIT         | 4   ->init code
  1993.                      |                       |
  1994.                      +-----------------------+
  1995.                      |       CA_RUN          | 8   ->run code
  1996.                      |                       |
  1997.                      +-----------------------+
  1998.                      |       CA_TIME         | $c  DOS time
  1999.                      +-----------------------+
  2000.                      |       CA_DATE         | $e  DOS date
  2001.                      +-----------------------+
  2002.                      |       CA_SIZE         | $10 "size" of appl.
  2003.                      |                       |
  2004.                      +-----------------------+
  2005.                      |       CA_NAME         | $14 asciz name
  2006.                      |                       |     (NNNNNNNN.EEE\0)
  2007.                      |                       |
  2008.                      |                       |
  2009.                      +-----------------------+
  2010.       
  2011.       
  2012.          CA_NEXT is a pointer to the next application header.   If
  2013.          CA_NEXT  is  $00000000, then there are no more headers in
  2014.          the list.
  2015.       
  2016.          CA_INIT is a pointer to the application's  initialization
  2017.          code.   If  CA_INIT  is  NULL, there is no initialization
  2018.          code.  The initialization  vector  is  called  at  system
  2019.          startup  time,  as  controlled  by magic bits in the high
  2020.          byte of this longword (see below).
  2021.       
  2022.          CA_RUN is a  pointer  to  the  application's  main  entry
  2023.          point.
  2024.       
  2025.          CA_TIME and CA_DATE are DOS-format time and date  stamps.
  2026.          [They  are  kind  of  useful for keeping track of version
  2027.          numbers and things like that, but are  otherwise  useless
  2028.          ....]
  2029.       
  2030.          CA_SIZE is a silly field that is the "size" of the appli-
  2031.          cation.   [This  field  is  pointless, but DRI wanted it,
  2032.          sooo ....]
  2033.       
  2034.          CA_NAME is the NULL-terminate name  of  the  application.
  2035.          It  should  be  in  the  same  format as a DOS acceptable
  2036.          filename, without a path (i.e. up to eight leading  char-
  2037.          acters,  optionally  followed  by  a  dot and up to three
  2038.          characters of extension, and a final NUL ($00)).
  2039.       
  2040.          The high 8 bits (24..31) of CA_INIT have special meaning:
  2041.              0 - Set to execute application (through CA_INIT  vec-
  2042.                  tor)  before  interrupt  vectors,  display memory
  2043.                  (etc.) have been initialized.
  2044.       
  2045.              1 - Set to execute application (through CA_INIT  vec-
  2046.                  tor) just before GEMDOS is initialized.
  2047.       
  2048.              2 - (unused)
  2049.       
  2050.              3 - Set to execute application (through CA_INIT  vec-
  2051.                  tor)  immediately  before  a  disk-boot.  [***FOR
  2052.                  NOW*** Applicable to boot ROM only.]
  2053.       
  2054.              4 - (unused)
  2055.       
  2056.              5 - Set if the application is a desk accessory.
  2057.       
  2058.              6 - Set if the application is NOT a GEM  application.
  2059.                  That is, it runs under DOS and doesn't do any AES
  2060.                  calls.
  2061.       
  2062.              7 - Set if non-GEM application (see bit  6)  requires
  2063.                  commandline parameters before execution.
  2064.       
  2065.       
  2066.                                 ~~~OOOO~~~
  2067.  
  2068.       
  2069.                          Vertical Blank Interrupts
  2070.                          -------------------------      
  2071.       
  2072.          This section describes the OS's Vertical Blank  Interrupt
  2073.          (VBI) handler, entered through the VBI vector at $70.
  2074.       
  2075.          The VBI handler increments the "frame counter"  'frclock'
  2076.          and then checks for mutual exclusion by testing 'vblsem'.
  2077.          If 'vblsem' is less than or equal to zero, no  other  VBI
  2078.          code  is executed.  Otherwise, all registers are saved on
  2079.          the stack and the "vblank counter"  'vbclock'  is  incre-
  2080.          mented.
  2081.       
  2082.          If  the  system  is  currently  in  high-resolution  mode
  2083.          (SHIFTMD  >= 2) and a low-resolution monitor is attached,
  2084.          the resolution is set  to  'defshiftmd'.   (or  zero,  if
  2085.          'defshiftmd'  is  >=  2).  This test is necessary because
  2086.          some low-resolution monitors may "burn up" when driven by
  2087.          the ST's high-resolution video signal.
  2088.       
  2089.          The handler calls the cursor-blink routine.
  2090.       
  2091.          If 'colorptr' is nonzero, then the 16 color palettes  are
  2092.          loaded  from  the  16  words  that  'colorptr' points to.
  2093.          'colorptr' is then zeroed.
  2094.       
  2095.          If 'screenpt' is nonzero, then the screen's physical base
  2096.          address set to 'screenpt'.  'screenpt' is then zeroed.
  2097.       
  2098.          There may be any number of "deferred" VBI vectors.  These
  2099.          are  executed  just  before the VBI handler returns.  The
  2100.          variable 'nvbls' contains the current number of  deferred
  2101.          vector  slots.   'vblqueue'  points  to  an array of NVBL
  2102.          pointer slots that in turn point to deferred VBI code  or
  2103.          NULL (in the case of an empty slot):
  2104.       
  2105.                                  +----------+
  2106.                                  |vblqueue o|----+
  2107.                                  +----------+    |
  2108.                                                  |
  2109.                       +--------------------------+
  2110.                       |
  2111.                       |   ........... 'NVBL' entries ..................
  2112.                       |  /                                               (
  2113.                       |  +-------+-------+-------+-------+-------+-------+
  2114.                       +->|   o   |       |       |   o   |       |       |
  2115.                          +---|---+-------+-------+---|---+-------+-------+
  2116.                              |                       |
  2117.                              +---> handler...        +---> handler...
  2118.       
  2119.       
  2120.          The OS initially allocates 8 VBI slots.  The  first  slot
  2121.          is  reserved for GEM's VBI code.  To add another deferred
  2122.          handler, place a pointer in a free (NULL) slot.  If there
  2123.          are no more free slots, then allocate a larger VBI array,
  2124.          copy the current vectors to the new array  (clearing  any
  2125.          new, unused entries), and update 'vblqueue' and 'nvbls'.
  2126.       
  2127.          Deferred VBI handlers should return with  RTS,  _ n_ o_ t  RTE.
  2128.          They may use any registers except the user stack-pointer.
  2129.       
  2130.          Applications are responsible for cleaning up  vbl-vectors
  2131.          they have installed prior to process termination.
  2132.       
  2133.       
  2134.                                 ~~~OOOO~~~
  2135.  
  2136.  
  2137.                          ROM System Initialization
  2138.                          -------------------------
  2139.       
  2140.          [1]  Initial PC set from  location  $FC0000,  initial  SP
  2141.               (trash, really) set from location $FC0004.
  2142.       
  2143.               Catch system RESET.  Raise processor IPL to 7,  exe-
  2144.               cute RESET instruction to reset hardware registers.
  2145.       
  2146.               If a diagnostic cartridge is inserted, load a return
  2147.               address into A6 and jump to the cartridge.
  2148.       
  2149.          [2]  If memory was setup (i.e. this is a  warmstart)  the
  2150.               initialize the memory controller.
  2151.       
  2152.          [3]  If the RESET-bailout vector is valid, load a  return
  2153.               address into A6 and jump to the reset handler.
  2154.       
  2155.          [4]  Initialize the PSG (deselect  floppies),  setup  the
  2156.               scan  rate (50 or 60hz), write default values to the
  2157.               color palettes,  and  set  the  display  pointer  to
  2158.               0x10000.
  2159.       
  2160.           If memory was sized on a previous reset, go to step 8.
  2161.       
  2162.          [5]  Size both banks of memory.
  2163.       
  2164.          [6]  [This used to perform a memory test.]
  2165.       
  2166.          [7]  Once memory has been sized and  zeroed,  record  the
  2167.               fact by setting two magic longwords in low memory.
  2168.       
  2169.          [8]  Clear the low 64K  of  memory,  from  'endosbss'  to
  2170.               0xffff.   Initialize  all  kinds  of  OS  variables.
  2171.               Setup interrupt vectors.  Call the serial BIOS' ini-
  2172.               tialization entry-point.
  2173.       
  2174.          [9]  Execute %%2 cartridge applications.
  2175.       
  2176.          Initialize the screen resolution.
  2177.       
  2178.          [11] Execute %%0 cartridge applications.
  2179.       
  2180.          [12] Enable interrupts (all but HBLANK) by  bringing  the
  2181.               IPL to 3.
  2182.       
  2183.          [13] Execute %%1 cartridge applications.
  2184.       
  2185.          [14] Call GEMDOS' initialization routine.
  2186.       
  2187.          [15] Attempt to boot from  floppy  disk,  if  the  system
  2188.               variable  'bootdev' is less than 2.  If there are no
  2189.               floppies, no attempt is made to boot from floppy.
  2190.       
  2191.               Attempt to load a boot sector from the DMA bus.  For
  2192.               each  of the eight DMA bus devices, a read operation
  2193.               is attempted on logical sector 0.  If  the  read  is
  2194.               successful,  and the sector checksums to $1234, then
  2195.               the sector is executed.  [See the section  "DMA  Bus
  2196.               Boot"]
  2197.       
  2198.               ALL devices are checked.  The boot sector  code  may
  2199.               return,  in which case the BIOS will attempt to load
  2200.               boot sectors from the rest of the devices.
  2201.       
  2202.          [16] Turn on the cursor.  Do autoexec.  Attempt  to  exec
  2203.               COMMAND.PRG.
  2204.       
  2205.          [17] Do autoexec.  Kludge up an enviroment string.   Exec
  2206.               the AES (in ROM).
  2207.       
  2208.          If [16] or [17] ever  complete,  restart  the  system  by
  2209.               going back to [1].
  2210.       
  2211.                           System
  2212.                           RESET
  2213.                             |
  2214.                             V
  2215.                  +-----------------------+
  2216.                  |       Diagnostic      | (1)
  2217.                  |    Cartridge check    |
  2218.                  +-----------------------+
  2219.                             |
  2220.                             V
  2221.                  +-----------------------+
  2222.                  |    Memory Controller  | (2)
  2223.                  |      (fast init)      |
  2224.                  +-----------------------+
  2225.                             |
  2226.                             V
  2227.                  +-----------------------+
  2228.                  |    RESET bailout      | (3)
  2229.                  |       vector          |
  2230.                  +-----------------------+
  2231.                             |
  2232.                             V
  2233.                  +-----------------------+
  2234.                  |    init PSG           | (4)
  2235.                  |    init 50hz/60hz     |
  2236.                  |    init palettes      |
  2237.                  |    display at $10000  |
  2238.                  +-----------------------+
  2239.                             |
  2240.                             V
  2241.                    ~~~~~~~~~~~~~~~~~~~~~
  2242.                   ~                     ~
  2243.             YES  ~   Has memory been     ~
  2244.               /-<    sized?  [is this     ~
  2245.               |  ~   a warmstart?]       ~
  2246.               |   ~                     ~
  2247.               |    ~~~~~~~~~~~~~~~~~~~~~
  2248.               |             |
  2249.               |          NO |
  2250.               |             |
  2251.               |             V
  2252.               |  +-----------------------+
  2253.               |  |    size memory        |
  2254.               |  |    and clear it       |
  2255.               |  +-----------------------+
  2256.               |             |
  2257.               |             V
  2258.               |  +-----------------------+
  2259.               |  |   indicate successful | (7)
  2260.               |  |       warmstart       |
  2261.               |  +-----------------------+
  2262.               |             |
  2263.               |             |
  2264.               \-------------\
  2265.                             |
  2266.                             V
  2267.                  +-----------------------+
  2268.                  |    Clear bottom 64K   | (8)
  2269.                  |    Init variables     |
  2270.                  |    Init interrupts    |
  2271.                  |    Init serial BIOS   |
  2272.                  +-----------------------+
  2273.                             |
  2274.                             V
  2275.                  +-----------------------+
  2276.                  | Execute %%2 cartridge | (9)
  2277.                  |      applications     |
  2278.                  +-----------------------+
  2279.                             |
  2280.                             V
  2281.                  +-----------------------+
  2282.                  |    Init screen        | (10)
  2283.                  |     resolution        |
  2284.                  +-----------------------+
  2285.                             |
  2286.                             V
  2287.                  +-----------------------+
  2288.                  | Execute %%0 cartridge | (11)
  2289.                  |      applications     |
  2290.                  +-----------------------+
  2291.                             |
  2292.                             V
  2293.                  +-----------------------+
  2294.                  |   Bring IPL to 3      | (12)
  2295.                  |                       |
  2296.                  +-----------------------+
  2297.                             |
  2298.                             V
  2299.                  +-----------------------+
  2300.                  | Execute %%1 cartridge | (13)
  2301.                  |      applications     |
  2302.                  +-----------------------+
  2303.                             |
  2304.                             V
  2305.                  +-----------------------+
  2306.                  |   Initialize GEMDOS   | (14)
  2307.                  |                       |
  2308.                  +-----------------------+
  2309.                             |
  2310.                             V
  2311.                  +-----------------------+ (15)
  2312.                  |   Attempt to boot     |>------\
  2313.                  |    from floppy        |<--\   | execute
  2314.                  +-----------------------+   |   | boot
  2315.                             |                |   | sector
  2316.                             |                \---/
  2317.                             |
  2318.                             V
  2319.                  +-----------------------+ (15a)
  2320.                  |   Poll devices on     |>------\
  2321.                  |   DMA bus, requesting |       |
  2322.                  |     boot sectors      |<--\   | execute
  2323.                  +-----------------------+   |   | boot
  2324.                             |                |   | sector
  2325.                             V                \---/
  2326.                    ~~~~~~~~~~~~~~~~~~~~~
  2327.                   ~                     ~
  2328.             YES  ~                       ~
  2329.               /-<    _cmdload == 0 ?      ~
  2330.               |  ~                       ~
  2331.               |   ~                     ~
  2332.               |    ~~~~~~~~~~~~~~~~~~~~~
  2333.               |             |
  2334.               |          NO |
  2335.               |             V
  2336.               |  +-----------------------+
  2337.               |  |   Turn on cursor      | (16)
  2338.               |  |   Exec \AUTO\*.PRG    |
  2339.               |  |   Exec COMMAND.PRG    |
  2340.               |  +-----------------------+
  2341.               |             |
  2342.               |             \--------------------\
  2343.               |                                  |
  2344.               \-------------\                    |
  2345.                             |                    |
  2346.                             V                    |
  2347.                  +-----------------------+       |
  2348.                  |   Exec \AUTO\*.PRG    | (17)  |
  2349.                  |   Kludge up enviro.   |       |
  2350.                  |       string          |       |
  2351.                  |   Exec AES (in ROM)   |       |
  2352.                  +-----------------------+       |
  2353.                             |                    |
  2354.                             |<-------------------/
  2355.                             |
  2356.                             V
  2357.                       Reset system,
  2358.                     start over again
  2359.       
  2360.       
  2361.                              ~~~OOOO~~~      
  2362.  
  2363.                             Boot Sectors
  2364.                             ------------      
  2365.       
  2366.          The boot sector contains
  2367.       
  2368.              o  A volume serial number
  2369.              o  A BIOS parameter block
  2370.              o  Optional boot code and boot parameters
  2371.       
  2372.          An executable boot sector must word-checksum to the magic
  2373.          number $1234.  During system initialization the boot sec-
  2374.          tor from a disk drive is loaded into a  buffer.   If  the
  2375.          checksum  is  correct,  the system JSRs the first byte of
  2376.          the  buffer.   [Since  the  location  of  the  buffer  is
  2377.          indeterminant, any code contained in the boot sector must
  2378.          be position-independent.] See the section on system  ini-
  2379.          tialization  for  further  details  on  writing  bootable
  2380.          applications.
  2381.       
  2382.          When a "Get BPB" call is made, the BIOS  reads  the  boot
  2383.          sector  and  examines  the prototype BIOS parameter block
  2384.          (BPB).  A BPB is constructed from the prototype.  If  the
  2385.          prototype looks strange (for instance, if critical fields
  2386.          in it are zero) the BIOS returns NULL (as an error  indi-
  2387.          cation).
  2388.       
  2389.          A BPB is normally computed and written when the volume is
  2390.          formatted.
  2391.       
  2392.          The 24-bit serial number is used to determine if the user
  2393.          has  changed disks.  (see the [still nonexistant] section
  2394.          on "Disk Changes").  The serial number  is  computed  and
  2395.          written by the FORMAT utility, and is (hopefully) unique.
  2396.       
  2397.                          +-----------------------+
  2398.                          |       BRA.S           | $0  branch to boot code
  2399.                          |       (wherever)      |
  2400.                          +-----------------------+
  2401.                          |       filler          | $2  reserved for OEMs
  2402.                          |                       |
  2403.                          |       (OEM            |
  2404.                          |        cruft)         |
  2405.                          |                       |
  2406.                          |                       |
  2407.                          +-----------------------+
  2408.                          |       SERIAL          | $8  volume serial number
  2409.                          |       24-bit volume   |     written by FORMAT
  2410.                          |       serial number   |
  2411.                          +-----------------------+
  2412.                          |l      BPS             | $b  #bytes/sector
  2413.                          |h                      |
  2414.                          +-----------------------+
  2415.                          |       SPC             | $d  #sectors/cluster
  2416.                          +-----------------------+
  2417.                          |l      RES             | $e  #reserved sectors
  2418.                          |h                      |
  2419.                          +-----------------------+
  2420.                          |       NFATS           | $10 #FATs
  2421.                          +-----------------------+
  2422.                          |l      NDIRS           | $11 #directory entries
  2423.                          |h                      |
  2424.                          +-----------------------+
  2425.                          |l      NSECTS          | $13 #sectors on media
  2426.                          |h                      |
  2427.                          +-----------------------+
  2428.                          |       MEDIA           | $15 media descriptor
  2429.                          +-----------------------+
  2430.                          |l      SPF             | $16 #sectors/FAT
  2431.                          |h                      |
  2432.                          +-----------------------+
  2433.                          |l      SPT             | $18 #sectors/track
  2434.                          |h                      |
  2435.                          +-----------------------+
  2436.                          |l      NSIDES          | $1a #sides on media
  2437.                          |h                      |
  2438.                          +-----------------------+
  2439.                          |l      NHID            | $1c #hidden sectors
  2440.                          |h                      |
  2441.                          +-----------------------+
  2442.                          |       boot code       | $1e
  2443.                          .       (if any)        .
  2444.       
  2445.                          |                       |
  2446.                          +-----------------------+
  2447.                                                    $200
  2448.       
  2449.          The prototype BPB is software compatible with  an  MS-DOS
  2450.          version  2.x  BPB.   (This  does not mean the ST can read
  2451.          sectors written by, or write sectors readable by, a  disk
  2452.          controller other than the WDC 1770/1772).
  2453.       
  2454.          The low byte of a 16-bit field in the BPB (such as 'BPS')
  2455.          occupies the lower address [as on the 8086.]
  2456.       
  2457.          BPS is the number of bytes per sector  (for  floppies  on
  2458.          the ST, it will be 512).
  2459.       
  2460.          SPC is the number of sectors per  cluster  (on  floppies,
  2461.          usually 2 for a cluster size of 1K).
  2462.       
  2463.          RES is the number of reserved sectors at the beginning of
  2464.          the  media,  including the boot sector.  RES is usually 1
  2465.          on floppies.
  2466.       
  2467.          NFATS is the number of  File  Allocation  Tables  on  the
  2468.          media.
  2469.       
  2470.          NDIRS is the number of directory entries.
  2471.       
  2472.          NSECTS is the  total  number  of  sectors  on  the  media
  2473.          (including the reserved sectors).
  2474.       
  2475.          MEDIA is a media descriptor byte.  The ST BIOS  does  not
  2476.          use this byte, but other file-systems might.
  2477.       
  2478.          SPF is the number of sectors in each FAT.
  2479.       
  2480.          SPT is the number of sectors per track.
  2481.       
  2482.          NSIDES is the number of sides  on  the  media.   (Single-
  2483.          sided  media  can be read on double-sided drives, but not
  2484.          vice-versa).
  2485.       
  2486.          NHID is the number of "hidden"  sectors.   (The  ST  BIOS
  2487.          currently ignores this value for floppies).
  2488.       
  2489.          The last word in the boot  sector  (at  offset  $1FE)  is
  2490.          reserved for "evening out" checksums.  In particular, the
  2491.          "_protobpb" extended BIOS function modifies this word.
  2492.       
  2493.       
  2494.                                 ~~~OOOO~~~
  2495.  
  2496.                          Formatting a Floppy Disk
  2497.                          ------------------------      
  2498.       
  2499.          [1] Use the 'flopfmt()' (#10.) extended BIOS call to for-
  2500.              mat  all tracks on the floppy disk.  If tracks 0 or 1
  2501.              have any bad sectors then the media is unusable.
  2502.       
  2503.              The ST standard format is
  2504.       
  2505.                  1 or 2 sides;
  2506.                  80 tracks;
  2507.                  9 sectors per track;
  2508.                  no interleave (sequential sectors).
  2509.       
  2510.       
  2511.              Zero the first two tracks (this will zero the FAT and
  2512.              directory sectors).
  2513.       
  2514.          [2] Use the 'protobt()'  (#18.)  extended  BIOS  call  to
  2515.              create  a  boot  sector.   The  'disktype'  parameter
  2516.              should be 2 or 3 for 1  or  2  sided  80-track  media
  2517.              respectively.   The  'serialno' parameter should be a
  2518.              random number (or $1000000).
  2519.       
  2520.              The 'execflag' parameter should be  zero  unless  the
  2521.              prototyping  buffer  contains code (such as a copy of
  2522.              the Loader) that you want executed when the  disk  is
  2523.              booted.
  2524.       
  2525.          [3] Write the boot sector, (prototyped in the  buffer  in
  2526.              step  [2])  to  track  0, side 0, sector 1 of the new
  2527.              disk.  Do NOT use the 'rwabs' call; use the  extended
  2528.              BIOS function 'flopwr'.
  2529.       
  2530.          It is possible to create disks in wierd formats by  vary-
  2531.          ing  the  number  of  sectors per track, formatting a few
  2532.          extra tracks, or specifying strange interleave factors.
  2533.       
  2534.          The 1772 "write track" codes used to format a track are:
  2535.       
  2536.              COUNT   BYTE    what
  2537.              -----   ----    ----------------
  2538.              60      $4e     (start of track)
  2539.       
  2540.              For each sector:
  2541.               12      $00
  2542.               3       $f5    (writes $a1)
  2543.               1       $fe    (ID address mark)
  2544.               1       track# (0..$4f)
  2545.               1       side#  (0..1)
  2546.               1       sector# (1..9)
  2547.               1       $02    (512 bytes/sector)
  2548.               1       $f7    (2 CRCs written)
  2549.               22      $4e
  2550.               12      $00
  2551.               3       $f5    (writes $a1)
  2552.               1       $fb    (data address mark)
  2553.               512     xx     (virgin data)
  2554.               1       $f7    (2 CRCs written)
  2555.               40      $4e
  2556.       
  2557.              End of track:
  2558.              1401    $4e     (filler at end of track)
  2559.       
  2560.       
  2561.                              ~~~OOOO~~~      
  2562.  
  2563.                          DMA Bus Boot Code
  2564.                          -----------------      
  2565.       
  2566.          This code, extracted from the ST's BIOS, attempts to load
  2567.          boot  sectors  from devices on the DMA bus.  The code can
  2568.          be used:
  2569.       
  2570.              o As an example of how to use the DMA bus (useful
  2571.                for boot-sector and device-driver writers);
  2572.       
  2573.              o To provide information about  the  timeout  and
  2574.                command  characteristics expected from bootable
  2575.                DMA bus devices;
  2576.       
  2577.          gpip            equ     $fffffa01       ; (B) 68901 input register
  2578.       
  2579.      diskctl         equ     $ffff8604       ; (W) disk controller data access
  2580.          fifo            equ     $ffff8606       ; (W) DMA mode control
  2581.          dmahigh         equ     $ffff8609       ; (B) DMA base high
  2582.          dmamid          equ     $ffff860b       ; (B) DMA base medium
  2583.          dmalow          equ     $ffff860d       ; (B) DMA base low
  2584.       
  2585.          flock           equ     $43e            ; (W) DMA chip lock variable
  2586.          _dskbufp        equ     $4c6            ; (L) -> 1K disk buffer
  2587.          _hz_200         equ     $4ba            ; (L) 200hz counter
  2588.       
  2589.    *+
  2590.    *  dmaboot - attempt to boot from a device on the DMA bus
  2591.    *    Passed:    nothing
  2592.    *
  2593.    *    Returns:   maybe-never (although it depends ...)
  2594.    *
  2595.    *    Uses:      everything
  2596.    *
  2597.    *    Discussion:
  2598.    *               Attempts to read boot sectors from eight devices connected
  2599.    *               to the DMA bus.  If a sector is read, and it is executable
  2600.    *               (word checksum is $1234), then it is executed.
  2601.    *
  2602.    *               This code should take about 0.5 sec to execute if nothing
  2603.    *               is connected to the DMA bus.  Of course, if something IS
  2604.    *               hooked up, it should provide us with a boot sector, right?
  2605.    *
  2606.    *-
  2607.          dmaboot:
  2608.                  moveq   #0,d7           ; start with dev #0
  2609.          dmb_1:  bsr     dmaread         ; attempt to read boot sector
  2610.                  bne     dmb_2           ; (failed -- try next dev)
  2611.                  move.l  _dskbufp,a0     ; a0 -> disk buffer
  2612.                  move.w  #$00ff,d1       ; checksum $100 words
  2613.                  moveq   #0,d0           ; checksum = 0
  2614.          dmb_3:  add.w   (a0)+,d0        ; add (next) word
  2615.                  dbra    d1,dmb_3
  2616.                  cmp.w   #bootmagic,d0   ; is the sector executable?
  2617.                  bne     dmb_2           ; (nope)
  2618.                  move.l  _dskbufp,a0     ; a0 -> disk buffer
  2619.                  jsr     (a0)
  2620.          dmb_2:  add.b   #$20,d7         ; next devno
  2621.                  bne     dmb_1           ; (do all eight devs)
  2622.                  rts
  2623.       
  2624.          *+
  2625.          *  dmaread - attempt to read boot sector from DMA bus device
  2626.          *    Passed:    d7.b = ddd00000
  2627.          *               ('ddd' is the ACSI device number, 0..7)
  2628.          *
  2629.          *    Returns:   NE: read failed;
  2630.          *               EQ: successful read,
  2631.          *                   sector data in (*_dskbufp)[];
  2632.          *
  2633.          *    Preserves: d7.w
  2634.          *
  2635.          *    Uses:      everything else
  2636.          *
  2637.          *
  2638.          *-
  2639.          dmaread:
  2640.                  lea     fifo,a6         ; a6 -> DMA control register
  2641.                  lea     diskctl,a5      ; a5 -> DMA data register
  2642.                  st      flock           ; lock up DMA against vblank
  2643.       
  2644.                  move.l  _dskbufp,-(sp)  ; setup DMA pointer
  2645.                  move.b  3(sp),dmalow
  2646.                  move.b  2(sp),dmamid
  2647.                  move.b  1(sp),dmahigh
  2648.                  addq    #4,sp
  2649.       
  2650.                  move.w  #$098,(a6)      ; toggle R/W, leave in Read state
  2651.                  move.w  #$198,(a6)
  2652.                  move.w  #$098,(a6)
  2653.                  move.w  #1,(a5)         ; write sector count register (= 1)
  2654.       
  2655.                  move.w  #$088,(a6)      ; select dma bus (not SCR)
  2656.       
  2657.                  move.b  d7,d0           ; setup d0.L with devno+command
  2658.          or.b    #$08,d0         ; d0.b = devno<<5 .OR. "READ" command bits
  2659.                  swap    d0
  2660.                  move.w  #$088,d0
  2661.  
  2662.            bsr     wcbyte          ; d0.L = xxxxxxxxDDD01000xxxxxxx010001010
  2663.            bne     dmr_q           ; (punt on timeout)
  2664.       
  2665.            moveq   #3,d6           ; (count = 4)
  2666.            move.l  #$0000008a,d0   ; d0.L = generic command ($0000)
  2667.    dmr_lp: bsr     wcbyte          ; write bytes 2, 3, 4 and 5
  2668.            bne     dmr_q           ; (punt on timeout)
  2669.            dbra    d6,dmr_lp       ; (loop for more bytes)
  2670.       
  2671.            move.l  #$0000000a,(a5) ; write byte 6 (final byte)
  2672.            move.w  #400,d1         ; timeout = 2.0 sec
  2673.            bsr     wwait           ; wait for completion
  2674.            bne     dmr_q           ; (punt on timeout)
  2675.       
  2676.            move.w  #$08a,(a6)      ; select status reg
  2677.            move.w  (a5),d0         ; get return code from DMA device
  2678.            and.w   #$00ff,d0       ; strip crufty bits
  2679.            beq     dmr_r           ; (return if OK)
  2680.       
  2681.    *--- reset DMA, return NE
  2682.    dmr_q:
  2683.            moveq   #-1,d0          ; return -1 (error)
  2684.    dmr_r:  move.w  #$080,(a6)      ; cleanup DMA chip for floppy driver
  2685.            tst.b   d0              ; (test for NE on return)
  2686.            sf      flock           ; unlock DMA chip
  2687.            rts                     ; return
  2688.       
  2689.       
  2690.    *+
  2691.    *  wcbyte - write ACSI command byte, wait for IRQ
  2692.    *    Passed:    D0.L = command byte and FIFO control
  2693.    *                       bits 16..23 = command byte,
  2694.    *                       bits 0..7 = FIFO control bits
  2695.    *               a5 -> $ff8604
  2696.    *
  2697.    *    Returns:   NE on failure (timeout)
  2698.    *               EQ on successful ACK
  2699.    *
  2700.    *    Uses:      d1
  2701.    *
  2702.    *-
  2703.    wcbyte:
  2704.            move.l  d0,(a5)         ; write WDC, WDL [due to jwt]
  2705.            moveq   #10,d1          ; wait 1/20th second
  2706.    wwait:  add.l   _hz_200,d1      ; d1 = time to quit at...
  2707.    ww_1:   btst.b  #5,gpip         ; disk done?
  2708.            beq     ww_w            ; (yes, return)
  2709.            cmp.l   _hz_200,d1      ; timeout?
  2710.            bne     ww_1            ; (not yet -- wait some more...)
  2711.            moveq   #-1,d1          ; ensure NE (timeout error) return
  2712.    ww_w:   rts
  2713.       
  2714.       
  2715.                                 ~~~OOOO~~~
  2716.  
  2717.  
  2718.                           Hard Disk Partitioning
  2719.                           ----------------------      
  2720.       
  2721.          The first sector (logical sector #0) on a hard disk  con-
  2722.          tains partition information.
  2723.       
  2724.       
  2725.                                               offset
  2726.                      +-----------------------+
  2727.                      |       hd_siz          | $1c2
  2728.                      |                       |
  2729.                      +-----------------------+
  2730.                      |       p0_flg          | $1c6
  2731.                      |       p0_id           | $1c7
  2732.                      |       p0_st           | $1ca
  2733.                      |                       |
  2734.                      |       p0_siz          | $1ce
  2735.                      |                       |
  2736.                      +-----------------------+
  2737.                      |       p1_flg          | $1d2
  2738.                      |       p1_id           | $1d3
  2739.                      |       p1_st           | $1d6
  2740.                      |                       |
  2741.                      |       p1_siz          | $1da
  2742.                      |                       |
  2743.                      +-----------------------+
  2744.                      |       p2_flg          | $1de
  2745.                      |       p2_id           | $1df
  2746.                      |       p2_st           | $1e2
  2747.                      |                       |
  2748.                      |       p2_siz          | $1e6
  2749.                      |                       |
  2750.                      +-----------------------+
  2751.                      |       p3_flg          | $1ea
  2752.                      |       p3_id           | $1eb
  2753.                      |       p3_st           | $1ee
  2754.                      |                       |
  2755.                      |       p3_siz          | $1f2
  2756.                      |                       |
  2757.                      +-----------------------+
  2758.                      |       bsl_st          | $1f6
  2759.                      |                       |
  2760.                      |       bsl_cnt         | $1fa
  2761.                      |                       |
  2762.                      +-----------------------+
  2763.                      |       (reserved)      | $200
  2764.                      +-----------------------+
  2765.       
  2766.       
  2767.          'hd_siz' is the total size of the disk, in  logical  sec-
  2768.          tors.
  2769.       
  2770.          'bsl_st' specifies the starting sector# of the bad sector
  2771.          list.   [Typically the bad sector list will be located at
  2772.          the end of the device.]
  2773.       
  2774.          'bsl_cnt' specifies the /number/ of  bad  sectors.   Each
  2775.          bad  sector  is  specified  by  a longword containing the
  2776.          sector's number.  The total number of sectors used up  by
  2777.          the  bad  sector  list  is  therefore  'bsl_siz' / 4.  If
  2778.          'bsl_cnt' is zero, there are no bad sectors.
  2779.       
  2780.          A disk may contain up to four partitions.  The first sec-
  2781.          tor  in  a  partition is a boot sector (which, on the ST,
  2782.          will contain a BPB).
  2783.       
  2784.       
  2785.                      +-----------------------+
  2786.                      |       root boot       |
  2787.                      +-----------------------+
  2788.       
  2789.                      +-----------------------+
  2790.                      |       partition 0     |
  2791.                      |                       |
  2792.                      +-----------------------+
  2793.       
  2794.                      +-----------------------+
  2795.                      |       partition 1     |
  2796.                      |       (optional)      |
  2797.                      +-----------------------+
  2798.       
  2799.                      +-----------------------+
  2800.                      |       partition 2     |
  2801.                      |       (optional)      |
  2802.                      +-----------------------+
  2803.       
  2804.                      +-----------------------+
  2805.                      |       partition 3     |
  2806.                      |       (optional)      |
  2807.                      +-----------------------+
  2808.       
  2809.                      +-----------------------+
  2810.                      |       optional        |
  2811.                      |       bad sector      |
  2812.                      |       list            |
  2813.                      +-----------------------+
  2814.       
  2815.          Each partition is described by a 12-byte structure:
  2816.       
  2817.                      +-----------------------+
  2818.                      |       p*_flg          | (+0)
  2819.                      +-----------------------+
  2820.                      |       p*_id           | (+1)
  2821.                      |                       |
  2822.                      |                       |
  2823.                      +-----------------------+
  2824.                      |       p*_st           | (+4)
  2825.                      |                       |
  2826.                      |                       |
  2827.                      |                       |
  2828.                      +-----------------------+
  2829.                      |       p*_siz          | (+8)
  2830.                      |                       |
  2831.                      |                       |
  2832.                      |                       |
  2833.                      +-----------------------+
  2834.                                                (+12.)
  2835.       
  2836.          'p*_flg' should be nonzero to indicate that the partition
  2837.          exists.   The BIOS will boot the first partition that has
  2838.          bit 7 set in this byte.
  2839.       
  2840.          'p*_id' is a three-byte field that identifies the  parti-
  2841.          tion.  For GEMDOS partitions, the field contain the three
  2842.          ascii characters "GEM".
  2843.       
  2844.          'p*_st' specifies the logical sector number of the begin-
  2845.          ning of the partition.
  2846.       
  2847.          'p*_siz' specifies the size of the partition, in  logical
  2848.          sectors.
  2849.       
  2850.       
  2851.                              ~~~OOOO~~~      
  2852.  
  2853.  
  2854.                              The Loader
  2855.                              ----------      
  2856.       
  2857.          The Loader is a generic system-loader.  It lives on  boot
  2858.          sectors, and is brought into RAM and executed during sys-
  2859.          tem initialization.  The Loader  has  the  capability  to
  2860.          load  an "image" file or a set of contiguous sectors from
  2861.          disk.
  2862.       
  2863.          The six reserved bytes starting at offset 2 in  the  boot
  2864.          sector must be:
  2865.       
  2866.                                  'Loader'
  2867.       
  2868.          for some tools to be able to manipulate Loader boot  sec-
  2869.          tors.
  2870.       
  2871.          An image file contains no header or  relocation  informa-
  2872.          tion.   It  is  an  exact image of the program to be exe-
  2873.          cuted.  The loader is capable of loading  any  file  from
  2874.          disk,  regardless of where it appears in the directory or
  2875.          whether the file is contiguous or not.
  2876.       
  2877.          Loader information immediately follows  the  BPB  in  the
  2878.          boot sector:
  2879.       
  2880.       
  2881.                      +-----------------------+
  2882.                      |       EXECFLG         | $1e
  2883.                      |                       | _cmdload
  2884.                      +-----------------------+
  2885.                      |       LDMODE          | $20
  2886.                      |                       | load mode
  2887.                      +-----------------------+
  2888.                      |       SSECT           | $22
  2889.                      |                       | sector start
  2890.                      +-----------------------+
  2891.                      |       SECTCNT         | $24
  2892.                      |                       | #sectors
  2893.                      +-----------------------+
  2894.                      |       LDADDR          | $26
  2895.                      |                       | load-address
  2896.                      |                       |
  2897.                      |                       |
  2898.                      +-----------------------+
  2899.                      |       FATBUF          | $2a
  2900.                      |                       | FAT address
  2901.                      |                       |
  2902.                      |                       |
  2903.                      +-----------------------+
  2904.                      |       FNAME   n       | $2e
  2905.                      |               n       |
  2906.                      |               n       |
  2907.                      |               n       |
  2908.                      |               n       |
  2909.                      |               n       |
  2910.                      |               n       |
  2911.                      |               n       |
  2912.                      |               e       |
  2913.                      |               e       |
  2914.                      |               e       |
  2915.                      +-----------------------+
  2916.                      |       (reserved)      | $39
  2917.                      +-----------------------+
  2918.                      |       BOOTIT          | $3a
  2919.                      |       code            |
  2920.                      .                       .
  2921.       
  2922.       
  2923.          EXECFLG is a word that is copied to '_cmdload'.
  2924.       
  2925.          LDMODE governs the loading mode.  If LDMODE  is  zero,  a
  2926.          file  is  searched for and loaded.  If LDMODE is nonzero,
  2927.          then 'SECTCNT'  sectors,  starting  with  logical  sector
  2928.          number 'SSECT', are loaded from the disk.
  2929.       
  2930.          SSECT is the logical sector number to start loading  from
  2931.          (valid iff LDMODE is nonzero).
  2932.       
  2933.          SECTCNT is the number  of  sectors  to  load  (valid  iff
  2934.          LDMODE is nonzero).
  2935.       
  2936.          LDADDR is the load-address of the file (or the sectors).
  2937.       
  2938.          FATBUF points to a place to put  the  FAT  and  directory
  2939.          sectors.
  2940.       
  2941.          FNAME is a filename to load (valid iff LDMODE  is  zero).
  2942.          It consists of eight character name and a three character
  2943.          extension.
  2944.       
  2945.          [See also: documentation on the BOOTGEN utility.]
  2946.       
  2947.       
  2948.                                 ~~~OOOO~~~
  2949.  
  2950.  
  2951.                               Boot Sequence
  2952.                               -------------      
  2953.       
  2954.             [1] The boot sector is loaded.  The Loader takes  con-
  2955.                 trol of the system.
  2956.       
  2957.             [2] The boot device's directory and 2nd FAT buffer are
  2958.                 read into memory, starting at _membot.  The Loader
  2959.                 searches for a file (usually) called TOS.IMG.   If
  2960.                 it  is not found, it returns with an error code in
  2961.                 D0.
  2962.       
  2963.             [3] TOS.IMG is read into memory, starting at $40000.
  2964.       
  2965.             [4] Control is passed to the first byte of TOS.IMG.
  2966.       
  2967.          TOS.IMG consists of three parts:
  2968.             [1] A relocator (RELOCRL) that moves TOS.IMG to  where
  2969.                 it  expects  to  be  executed  in memory.  RELOCRL
  2970.                 takes control of the  system,  fades  the  screen,
  2971.                 performs  a fast block-copy, and passes control to
  2972.                 the first byte in the operating system.
  2973.       
  2974.             [2] An image of the operating system ('prox 90K).
  2975.       
  2976.             [3] An image of the desktop and GEM ('prox 110K).
  2977.       
  2978.          System initialization  proceeds  as  normal  (except  for
  2979.          clearing memory) once the OS has control.
  2980.       
  2981.       
  2982.                                 ~~~OOOO~~~
  2983.  
  2984.  
  2985.                                  Boot ROM
  2986.                                  --------      
  2987.       
  2988.          The ST boot ROM (AKA "Das Boot") contains a subset of the
  2989.          BIOS.   The  only  functions  available relate to reading
  2990.          floppy disks.
  2991.       
  2992.          System initialization is identical to the normal OS  pro-
  2993.          cedure.  However, the locations and intepretations of the
  2994.          system variables may have changed.  See the end  of  this
  2995.          section for a list of "safe" system variables.
  2996.       
  2997.          The normal course of events is:
  2998.       
  2999.              The boot ROM catches RESET  and  initializes  the
  3000.              system.    It   puts  up  some  pretty  graphics.
  3001.              Kids'll love it.
  3002.       
  3003.              An attempt is made to boot  from  both  floppies.
  3004.              '_bootdev'  will  contain  the device number on a
  3005.              successful boot sector load.  [Someday there  may
  3006.              be  a  version  of  the boot ROM that understands
  3007.              about hard disks.]
  3008.       
  3009.              The boot sector is executed.  [See-also: Loader]
  3010.       
  3011.       
  3012.          Das Boot's version number (the second word in the ROM, at
  3013.          $FC0002) is $0000.
  3014.  
  3015.          BIOS functions on trap 13:
  3016.       
  3017.               func   Name [see: GEMDOS spec]
  3018.               ----   --------
  3019.                 0:   [unused]
  3020.                 1:   [unused]
  3021.                 2:   [unused]
  3022.                 3:   [unused]
  3023.                 4:   rwabs (read only)
  3024.                 5:   [unused]
  3025.                 6:   [unused]
  3026.                 7:   getbpb
  3027.       
  3028.          Extended functions on trap 14:
  3029.       
  3030.               func   Name [see: Extended BIOS Functions]
  3031.               ----   --------
  3032.                 0:   [unused]
  3033.                 1:   ssbrk
  3034.                 2:   [unused]
  3035.                 3:   [unused]
  3036.                 4:   [unused]
  3037.                 5:   [unused]
  3038.                 6:   [unused]
  3039.                 7:   [unused]
  3040.                 8:   _floprd (read sectors)
  3041.       
  3042.          DAS BOOT uses memory from $10000  to  $20000  for  screen
  3043.          buffers.  Avoid loading stuff into this region (until you
  3044.          take over  the  system)  when  writing  directly-bootable
  3045.          applications.
  3046.       
  3047.          Between the time when DAS BOOT was released and the  time
  3048.          the  first  RAM-loaded  systems  were  shipped  (will  be
  3049.          shipped?) the variables in low memory were added  to  and
  3050.          relocated.
  3051.       
  3052.          <<<give list of "safe" variables here>>>
  3053.       
  3054.       
  3055.                              ~~~OOOO~~~      
  3056.       
  3057.  
  3058.                              GEMDOS CALL
  3059.                              ----------- 
  3060.                       (QUICKER) REFERENCE GUIDE
  3061.                       -------------------------
  3062.       
  3063.          Functions are  available  through  trap  #1.   The  first
  3064.          number  is  the trap number (first word on the stack when
  3065.          the trap is made).  The  function's  name  (as  given  in
  3066.          OSBIND.H)  is  next, along with the named arguments.  The
  3067.          number in brackets is the number of bytes  that  must  be
  3068.          cleaned  up  off  the  stack  after the call is made (for
  3069.          those of us doing traps  from  assembly).   The  argument
  3070.          declarations  (if  any)  follow  the  first line.  Then a
  3071.          short description of the function is given.
  3072.       
  3073.          In general, GEMDOS calls return LONGs  in  D0.   However,
  3074.          there  /are/ exceptions.  When testing for error returns,
  3075.          it is best to examine D0.W only.  In addition, GEMDOS may
  3076.          occasionally  return BIOS error numbers (that is, between
  3077.          -1 and -31).
  3078.       
  3079.       
  3080.          $00 Pterm0() [2]
  3081.                    Terminate process (with return code of $0).
  3082.       
  3083.          $01 Cconin() [2]
  3084.                    Return cooked character from stdin.
  3085.       
  3086.          $02 Cconout(chr) [4]
  3087.              char chr;
  3088.                    Write character to stdout.
  3089.       
  3090.          $03 Cauxin() [2]
  3091.                    Return character from AUX:.
  3092.       
  3093.          $04 Cauxout(chr) [4]
  3094.              char chr;
  3095.                    Write character to AUX:.
  3096.       
  3097.          $05 Cprnout(chr) [4]
  3098.              char chr;
  3099.                    Write character to PRN:.
  3100.       
  3101.          $06 Crawio(wrd) [4]
  3102.              WORD wrd;
  3103.                    If (wrd == 0x00ff) return char from stdin
  3104.                    If (wrd != 0x00ff) print it on stdout;
  3105.       
  3106.          $07 Crawcin() [2]
  3107.                    Return raw character from stdin (without echo).
  3108.       
  3109.          $08 Cnecin() [2]
  3110.                    Read char from  stdin  without  echo.   Control
  3111.                    characters  (^S,  ^Q,  ^C)  are interpreted and
  3112.                    have effect.
  3113.       
  3114.          $09 Cconws(str) [6]
  3115.              char *str;
  3116.                    Write null-terminated string to stdout.
  3117.       
  3118.          $0a Cconrs(buf) [6]
  3119.              char *buf;
  3120.                    Read  edited  string  from  stdin.   On  entry,
  3121.                    buf[0] contains size of data part of buf[].  On
  3122.                    exit, buf[1] contains number of  characters  in
  3123.                    data  part  of  buf[].   The data part of buf[]
  3124.                    starts at buf[2].
  3125.       
  3126.          $0b Cconis() [2]
  3127.                    Return -1 [nonzero] if character  is  available
  3128.                    on stdin, 0 otherwise.
  3129.       
  3130.          $0e Dsetdrv(drv) [4]
  3131.              WORD drv;
  3132.                    Select  current  drive  (0=A:,   1=B:,   etc.).
  3133.                    Returns a bitmap of drives in the system (bit 0
  3134.                    = A, ....)
  3135.       
  3136.          $10 Cconos() [2]
  3137.                    Returns -1 [nonzero] if  console  is  ready  to
  3138.                    receive a character, 0 if it is "unavailable."
  3139.       
  3140.          $11 Cprnos() [2]
  3141.                    Returns  -1  [nonzero]  if  PRN:  is  ready  to
  3142.                    receive a character, 0 if it is "unavailable."
  3143.       
  3144.          $12 Cauxis() [2]
  3145.                    Returns -1 [nonzero] if char  is  available  on
  3146.                    AUX:, 0 otherwise.
  3147.       
  3148.          $13 Cauxos() [2]
  3149.                    Returns  -1  [nonzero]  if  AUX:  is  ready  to
  3150.                    receive a character, 0 if it is "unavailable."
  3151.       
  3152.          $19 Dgetdrv() [2]
  3153.                    Returns number of current drive (0=A:, etc.)
  3154.       
  3155.          $1a Fsetdta(ptr) [6]
  3156.              LONG ptr;
  3157.                    Set disk transfer address (used by Fsfirst()).
  3158.       
  3159.          $20 Super(stack) [6]
  3160.              LONG stack;
  3161.                    Hack processor privelege mode.  If  'stack'  is
  3162.                    -1L,  return  0  or  1 (processor is in user or
  3163.                    supervisor mode).  If in user mode,  switch  to
  3164.                    supervisor mode and use 'stack' as the supervi-
  3165.                    sor stack (or the value from USP if 'stack'  is
  3166.                    NULL).   If  in supervisor mode, switch to user
  3167.                    mode and use 'stack' as the  supervisor  stack.
  3168.                    Return the old supervisor stack value.
  3169.       
  3170.          $2a Tgetdate() [2]
  3171.                    Returns date:
  3172.       
  3173.                        bits
  3174.                        0..4    day 1..31
  3175.                        5..8    month 1..12
  3176.                        9..15   year 0..119 since 1980
  3177.       
  3178.          $2b Tsetdate(date) [4]
  3179.              WORD date;
  3180.                    Set date in the format described above.
  3181.       
  3182.          $2c Tgettime() [2]
  3183.                    Return time in the format:
  3184.       
  3185.                        bits
  3186.                        0..4    second 0..59 (2-second resolution)
  3187.                        5..10   minute 0..59
  3188.                        11..15  hour 0..23
  3189.       
  3190.          $2d Tsettime(time) [4]
  3191.              WORD time;
  3192.                    Set time in the format described above.
  3193.       
  3194.          $2f Fgetdta() [2]
  3195.                    Return current DTA.
  3196.       
  3197.          $30 Sversion() [2]
  3198.                    Return current version number.
  3199.       
  3200.          $31 Ptermres(keep, ret) [8]
  3201.              LONG keep;
  3202.              WORD ret;
  3203.                    Terminate and stay resident.  'keep' has number
  3204.                    of  bytes  to  keep  in the process descriptor.
  3205.                    'ret' is the process' return code.
  3206.       
  3207.          $36 Dfree(buf, drv) []
  3208.              LONG buf;
  3209.              WORD drv;
  3210.       
  3211.                    Return information about  allocation  on  drive
  3212.                    'drv'  (0=current,  1=A:,  2=B:,  etc.).  'buf'
  3213.                    points to  a  structure  where  stuff  will  be
  3214.                    returned:
  3215.       
  3216.                        LONG b_free;    #free clusters on drive
  3217.                        LONG b_total;   total #clusters on drive
  3218.                        LONG b_secsiz;  #bytes in a sector
  3219.                        LONG b_clsiz;   #sectors in a cluster
  3220.       
  3221.          $39 Dcreate(path) [6]
  3222.              char *path;
  3223.                    Create a directory.
  3224.       
  3225.          $3a Ddelete(path) [6]
  3226.              char *path;
  3227.                    Delete a directory.
  3228.       
  3229.          $3b Dsetpath(path) [6]
  3230.              char *path;
  3231.                    Set current directory.
  3232.       
  3233.          $3c Fcreate(name, attr) [8]
  3234.              char *name;
  3235.              WORD attr;
  3236.                    Create a file with the given pathname.  Returns
  3237.                    a  handle  or a (negative) error#.  Bits in the
  3238.                    attribute word are:
  3239.       
  3240.                        $01     set to readOnly
  3241.                        $02     hidden from directory search
  3242.                        $04     system file, hidden from dir search
  3243.                        $08     volume label (first 11 bytes of name)
  3244.       
  3245.          $3d Fopen(name, mode) [8]
  3246.              char *name;;
  3247.              WORD mode;
  3248.                    Open a file.  Mode is  0,  1  or  2  for  read,
  3249.                    write,  and  read/write.  Returns a handle or a
  3250.                    (negative) error#.
  3251.       
  3252.          $3e Fclose(handle) [4]
  3253.              WORD handle;
  3254.                    Close the handle.
  3255.       
  3256.          $3f Fread(handle, count, buf) [12]
  3257.              WORD handle;
  3258.              LONG count;
  3259.              char *buf;
  3260.                    Read bytes from a file.  Return count read,  or
  3261.                    a negative error#.
  3262.       
  3263.          $40 Fwrite(handle, count, buf) [12]
  3264.              WORD handle;
  3265.              LONG count;
  3266.              char *buf;
  3267.                    Write bytes to a file.  Return  count  written,
  3268.                    or a negative error#.
  3269.       
  3270.          $41 Fdelete(name) [6]
  3271.              char *name;
  3272.                    Delete the file.
  3273.       
  3274.          $42 Fseek(offset, handle, mode) [10]
  3275.              LONG offset;
  3276.              WORD handle;
  3277.              WORD mode;
  3278.                    Seek within the file (handle).  'offset' is the
  3279.                    (signed)  number  of bytes to seek by.  Mode is
  3280.                    one of:
  3281.       
  3282.                        0       from beginning of file
  3283.                        1       from current position
  3284.                        2       from end of file
  3285.       
  3286.          $43 Fattrib(path, mode, mode) [10]
  3287.                    Get file attributes if 'mode' is 0, set them if
  3288.                    'mode' is 1.  Bits are:
  3289.       
  3290.                        $01     readOnly
  3291.                        $02     hidden
  3292.                        $04     system (hidden hidden)
  3293.                        $08     volume label
  3294.                        $10     subdirectory
  3295.                        $20     written to and closed
  3296.       
  3297.          $45 Fdup(stdhandle) [4]
  3298.              WORD stdhandle;
  3299.                    Returns non-standard handle that refers to  the
  3300.                    same file.
  3301.       
  3302.          $46 Fforce(stdhandle, nonstdhandle) [6]
  3303.              WORD stdhandle;
  3304.              WORD nonstdhandle;
  3305.                    Force standard handle to point to same file  or
  3306.                    dev as the nonstandard handle.
  3307.       
  3308.          $47 Dgetpath(pathbuf, drv) [8]
  3309.              char *pathbuf;
  3310.              WORD drv;
  3311.                    Return  current  directory  for   drive   'drv'
  3312.                    (0=default,  1=A:, etc.) in the buffer.  Buffer
  3313.                    must be at least 64 bytes long.
  3314.       
  3315.          $48 Malloc(amount) [6]
  3316.              LONG amount;
  3317.                    'amount' contains # bytes to allocate  (or  -1,
  3318.                    which   returns   maximum   available  memory).
  3319.                    Return pointer to block (on word  boundary)  of
  3320.                    'amount' bytes, or zero on allocation failure.
  3321.       
  3322.          $49 Mfree(addr) [6]
  3323.              char *addr;
  3324.                    Free a block  of  memory.   Nonzero  return  on
  3325.                    failure.
  3326.       
  3327.          $4a Mshrink(zero, mem, size) [12]
  3328.              WORD zero;
  3329.              LONG mem;
  3330.              LONG size;
  3331.                    'zero' must be a word containing 0.  'mem' con-
  3332.                    tains beginning of memory block.  'size' is the
  3333.                    the amount of memory to RETAIN  in  the  block.
  3334.                    Nonzero return on failure.
  3335.       
  3336.          $4b Pexec(mode, path, commandline, enviroment) [16]
  3337.              WORD mode;
  3338.              char *path;
  3339.              char *commandline;
  3340.              char *enviroment;
  3341.                    'mode' is one of:
  3342.       
  3343.                        0       load and go
  3344.                        3       just load
  3345.                        4       create basepage
  3346.                        5       just go
  3347.       
  3348.                    'commandline' is the  command  tail,  which  is
  3349.                    copied  into the basepage.  'enviroment' is the
  3350.                    enviroment string; if NULL, the parent process'
  3351.                    enviroment string is inheirited.
  3352.       
  3353.                    For mode 0, the  return  code  is  the  child's
  3354.                    return  code, or a negative (OS) error.  If the
  3355.                    load or create-basepage fails, a negative error
  3356.                    number is returned.
  3357.       
  3358.          $4c Pterm(code) [4]
  3359.              WORD code;
  3360.                    Terminate current process, returning 'code'  to
  3361.                    the parent.
  3362.       
  3363.          $4e Fsfirst(spec, attr) [8]
  3364.              char *spec;
  3365.              WORD attr;
  3366.                    'attr' is a set of  attributes  to  match  (see
  3367.                    function  #43 for details).  'spec' may contain
  3368.                    wildcard characters in the filename, but not in
  3369.                    the  pathname.   Returns  0 if a file is found,
  3370.                    EFILNF if no file was found.  Dumps stuff  into
  3371.                    the DTA:
  3372.       
  3373.                        bytes
  3374.                        0..20   junk
  3375.                        21      file attributes
  3376.                        22-23   file time stamp
  3377.                        24-25   file date stamp
  3378.                        26-29   file size (longword)
  3379.                        30-43   name+extension of found file
  3380.       
  3381.          $4f Fsnext() [2]
  3382.                    Continue with with Fsfirst().
  3383.       
  3384.          $56 Frename(zero, old, new) [12]
  3385.              WORD zero;
  3386.              char *old;
  3387.              char *new;
  3388.                    Change the name of a file from 'old' to  'new'.
  3389.                    'zero' is reserved, and must be 0.
  3390.       
  3391.          $57 Fdatime(handle, buf, set) [10]
  3392.              WORD handle;
  3393.              char *buf;
  3394.              WORD set;
  3395.                    'buf' points to buffer containing file date and
  3396.                    time  information.  'handle' is a handle to the
  3397.                    file.  If 'set' is zero, get the time and date.
  3398.                    If 'set' is 1, set the file time and date.
  3399.       
  3400.       
  3401.                              ~~~OOOO~~~      
  3402.       
  3403.  
  3404.                       Atari Corp. Confidential
  3405.       
  3406.       
  3407.  
  3408.